Question

i want to get like wildcard query to search by second word

here few column data

sea food
food restaurant
Chinese food

if i search for "foo". it should return

sea food
Chinese food

how can i do that in MySQL

Was it helpful?

Solution 2

use regexp in your sql query .. something like

select * from table where col regexp '^[A-Za-z]+\s(foo).*$'

EDIT

used your table .. try this ..

select id,col from food where col regexp '^[A-Za-z]+ (foo)'

OTHER TIPS

How about:-

select * from table where food_name like '% foo%'

Use Below query. This will help in your case.

select column-name-list from table-name 
where right(your-desired-column-name,4) = 'food';

Here is one way of doing it

select * from
test
where 
substring_index(food_name,' ',-1) like '%foo%'
AND 
(
   LENGTH(food_name) - LENGTH( substring_index(food_name,' ',-1)) > 0
 )
;

DEMO

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top