Reputation: 15733
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 :)
Upvotes: 0
Views: 72
Reputation: 39773
select *
from `keywordtable`
where 'aaabbbcccc' like CONCAT('%',`keyword`,'%')
Upvotes: 3
Reputation: 265648
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
Upvotes: 0