Search code examples
mysqlsql-like

How use like for two fields and one value in mysql?


I have query like this :

select * from users where `firstname` like '%jack%' or `lastname` like '%Mr green%' 

But this code is not suitable when I want to find person that her first name is jack and her last name is Mr green or firstname is jack Mr and lastname is green.
in other word i have one textbox and user fill this textbox with firstname and lastname with one space between them , and i want search in users table and find users that search with searcher (searcher is who fill textbox).
Is there way to use like for two columns ?


Solution

  • i think if name is value you can use this

     (`firstname` like '%value%' or `lastname` like '%value%' or concat(firstname,' ', lastname) LIKE '%value%')