开发者

how to implement "contains" function in Mysql4.x?

开发者 https://www.devze.com 2023-01-07 15:17 出处:网络
i have a keywords table,and i want to ch开发者_如何学运维eck a String contains keyword or not.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消