James and David:

Thanks a lot for that.

1. select BadWords from WordsTable where locate (Badwords, "this is a test");

works , and

2. select BadWords from WordsTable where "this is test" like concat('%',
BadWords, '%');

works as well.

I can choose either one now.

Many thanks again.

Louis.


>I have a string for e.g. called "this is a test" . I would like to search
the
>SQL databases to see if any of the words in that string can be found in the
>forbidden words sql database. The databases itself just have one column with
>rows of restricted words. A sample of this DB is shown below
>
>1. select BadWords FROM WordsTable WHERE "this is a test" LIKE BadWords;
>2. select BadWords FROM WordsTable WHERE "this is a test" LIKE "%BadWords%";
>3. select BadWords FROM WordsTable WHERE BadWords LIKE "this is a test";
>  
>
So you want to find all the words which are a substring of the string 
you pass in?

I don't have mysql around to test on but the query you're looking for 
uses LOCATE. Something like this:

select BadWords from WordsTable where locate (Badwords, "this is a test");

% won't help. It's just a glob basically.

HTH

James.




--
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug

Reply via email to