How to do a LIKE considering two columns?

RedDragon picture RedDragon · Aug 11, 2011 · Viewed 13k times · Source

I have a customer table with two columns first_name and last_name.

How can I use LIKE in a query being able to get data from both columns at same tame?

For instance:

SELECT CONCAT(first_name, ' ', last_name) as 'full_name' 
FROM customer WHERE full_name LIKE 'John D%'

I've tried this and it tells me full_name column doesn't exist.

Answer

Ned Batchelder picture Ned Batchelder · Aug 11, 2011
SELECT CONCAT(first_name, ' ', last_name) as 'full_name' 
FROM customer WHERE CONCAT(first_name, ' ', last_name) LIKE 'John D%'