MySQL - CONCAT two fields and use them in WHERE clause
14,355
Try this ::
SELECT CONCAT_WS(' ', first_name, last_name) AS name FROM `users`
WHERE CONCAT_WS(' ', first_name, last_name) LIKE "%John Doe%"
Related videos on Youtube
Comments
-
yoda over 1 year
As the title suggests, I was wondering how to
concat
two fields in awhere clause
inmysql
. 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
andlast_name
are separate fields, and I want to enable myPHP
application to search for a full person's name.Any tips?
Cheers!
-
yoda almost 12 yearsThanks, that did the trick. I was actually expecting some way to use the aliased field in
where clause
, don't know if it's possible.