Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql Concat two columns while searching with LIKE

Tags:

mysql

I am trying to make a MySQL query where I filter the records based on the search text using LIKE keyword.

For example if the user searches for Illusion Softwares where Illusion is First name and Softwares is last name so the query should search for columns FirstName, LastName and concat both and search.

I have tried this so far but it does not work for CONCAT

 Select Contacts.*, Contacts.ID as CID from Contacts left join
 website_Data  on Contacts.ID = website_Data.ContactID where
 Contacts.`FirstName` LIKE '%Illusion Softwares%' or 
 Contacts.`LastName` LIKE '%Illusion Softwares%' or
 concat(Contacts.FirstName, ' ', Contacts.LastName) 
 LIKE '%Illusion Softwares%'
 or Contacts.Email LIKE '%Illusion Softwares%' 
 order by Contacts.`Created` DESC

What am I missing? Please help me.

like image 805
Yunus Aslam Avatar asked Nov 30 '22 17:11

Yunus Aslam


1 Answers

Your query should be like this

Select Contacts.*, Contacts.ID as CID 
from Contacts 
left join website_Data 
on Contacts.ID = website_Data.ContactID 
where CONCAT(Contacts.FirstName,' ', Contacts.LastName) LIKE '%Illusion Softwares%' 
order by Contacts.`Created` DESC 
like image 152
AbuHuraira Lakdawala Avatar answered Dec 06 '22 11:12

AbuHuraira Lakdawala