问题
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!
回答1:
Try this ::
SELECT CONCAT_WS(' ', first_name, last_name) AS name FROM `users`
WHERE CONCAT_WS(' ', first_name, last_name) LIKE "%John Doe%"
回答2:
pick up the users as view then query outside select query
select name from (select first_name||last_name FROM `users`
WHERE frst_name LIKE "%John%" or last name like "%doe%") where name like '%John Doe%'
来源:https://stackoverflow.com/questions/11140647/mysql-concat-two-fields-and-use-them-in-where-clause