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.
SELECT CONCAT(first_name, ' ', last_name) as 'full_name'
FROM customer WHERE CONCAT(first_name, ' ', last_name) LIKE 'John D%'
You are almost there
SELECT *
FROM customer
WHERE CONCAT(first_name, ' ', last_name) LIKE 'John D%'
Note: this may not have very good performance. You might want to consider full text search.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With