i have a keywords table,and i want to ch开发者_如何学运维eck 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 :)
select *
from `keywordtable`
where 'aaabbbcccc' like CONCAT('%',`keyword`,'%')
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
精彩评论