Using mysql concat() in WHERE clause?

后端 未结 7 2021
旧巷少年郎
旧巷少年郎 2020-11-29 00:59

I would like to search my table having a column of first names and a column of last names. I currently accept a search term from a field and compare it against both columns

7条回答
  •  佛祖请我去吃肉
    2020-11-29 01:38

    What you have should work but can be reduced to:

    select * from table where concat_ws(' ',first_name,last_name) 
    like '%$search_term%';
    

    Can you provide an example name and search term where this doesn't work?

提交回复
热议问题