Search code examples
mysqlsql-like

msql like function logical or


select town_id,name from `soft_uni`.towns
where name like 'b%' or 'm%' or 'k%' or 'e%'

I want to find all of the names that start with b or m or k or e, but like that it only works for the towns that start with b


Solution

  • You need to add name like before you start a condition in that query

    select town_id,name from `soft_uni`.towns
    where name like 'b%' or name like 'm%' or name like 'k%' 
          or name like 'e%'
    

    Another solution would be to use REGEXP

    select town_id, name from `soft_uni`.towns
    where name REGEXP '^(b|m|k|e)';