MySQL - CONCAT two fields and use them in WHERE clause

mysql, string-concatenation

Solution

Try this ::

SELECT CONCAT_WS(' ', first_name, last_name) AS name FROM `users`
WHERE CONCAT_WS(' ', first_name, last_name) LIKE "%John Doe%"

Problem

As the title suggests, I was wondering how to `concat` two fields in a `where clause` in `mysql`. This is an example of what I'm trying to achieve : ``` SELECT CONCAT_WS(' ', first_name, last_name) AS name FROM `users` WHERE name LIKE "%John Doe%" ``` The point is that `first_name` and `last_name` are separate fields, and I want to enable my `PHP` application to search for a full person's name. Any tips? Cheers!

Original source