I have this records from my users table:
user_id first_name last_name gender email
******* ********** ********* ****** *****
229 Natalie Fern F [email protected]
and I want to search same First Name & Last Name from first_name OR last_name.
I have created sql query but not getting record.
SELECT *
FROM user_detail
WHERE first_name LIKE '%Natalie Fern%'
OR last_name LIKE '%Natalie Fern%'
LIMIT 0 , 30
You notice that I am passing first & last name from both fields.
Any Idea why I am not getting records?
Thanks.
You are using the
LIKEoperator forfirst_nameandlast_nameas follows:This will only match strings which contain anything followed by 'Natalie Fern' followed by anything. But since the first and last name columns only contain (surprise) the first and last names, your query isn't matching any records. You can use
CONCATto try to match the combination of first and last names:If you want to check for people whose first or last names could be 'Natalie' or 'Fern', then you could use this query: