我有一张这样的表
id, title 1, hello world 2, world hello
并且我想搜索与此php表达式匹配的所有ID:
$searchstring = "hello world is yours"
if (strstr($searchstring,mysql(title)){echo found}
在mysql中我经常使用它:
select id from table where title LIKE '%....%'
但我需要另一面:
select id from table where "hello word is yours" LIKE %title%
结果必须是id 1“hello word”
任何人都可以告诉我正确的语法吗?
答案 0 :(得分:2)
select id from table
where 'hello word is yours' LIKE concat('%', replace(title, ' ', '%'), '%')
答案 1 :(得分:1)
使用CONCAT
select id
from tableName
where 'hello word is yours' LIKE CONCAT('%',title,'%')
答案 2 :(得分:1)
作为替代方案,您可以考虑使用Full Text Search。如果您创建FTS索引,它可以更有效,并提供直观的搜索字符串:
SELECT id FROM tablename WHERE MATCH (title)
AGAINST ('hello world is yours' IN BOOLEAN MODE);