Search code examples
mysqlregexwildcardsql-like

how to do like query in MySQL find second word in string


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


Solution

  • 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)'