我希望得到通配符查询来搜索第二个单词
这里列数据很少
sea food
food restaurant
Chinese food
如果我搜索“foo”。它应该回来
sea food
Chinese food
我怎么能在MySQL中做到这一点
在你的SQL查询中使用regexp ..类似于
select * from table where col regexp '^[A-Za-z]+\s(foo).*$'
编辑
用过你的桌子..试试这个..
select id,col from food where col regexp '^[A-Za-z]+ (foo)'
怎么样:-
select * from table where food_name like '% foo%'
使用以下查询。这对你的情况有帮助。
select column-name-list from table-name
where right(your-desired-column-name,4) = 'food';
这是一种做法
select * from
test
where
substring_index(food_name,' ',-1) like '%foo%'
AND
(
LENGTH(food_name) - LENGTH( substring_index(food_name,' ',-1)) > 0
)
;