views:

20

answers:

2

i have a keywords table,and i want to check a String contains keyword or not.

String str="aaabbbccc";

TableName:keywordTable
field:id keyword
-------------------
1 ee
2 bbb
3 xx
..
------------------

i run this sql (in mysql 4.1):

select * from `keywordTable` where contains(`keyword`,"aaabbbccc");

return a syntax error

how to implement it? (in mysql 4.1 and 4.0)

thanks :)

A: 
select *
from `keywordtable`
where `keyword` like '%aaabbbcccc%'

the only problem is, that it searches case-insensitive, so AAAAAABBBCCCCCCCCDDD will also be matched

edit. i misread, you want to match the other way round. do this instead:

select *
from `keywordtable`
where 'aaabbbcccc' like '%'+`keyword`+'%'

mysql also understands like in reversed order

knittl
keyword=='aa'string =='aaabbbccc'select * from `keywordtable` where `keyword` like '%aaabbbccc%' ? i think this not right.
Zenofo
+3  A: 
select *
from `keywordtable`
where  'aaabbbcccc' like CONCAT('%',`keyword`,'%')
Konerak
+1, made my answer redundant
David Hedlund