본문 바로가기
MySql

MySQL LIKE로 검색하는 동안 Mysql Concat 두 열

by 베이스 공부 2020. 11. 18.
반응형

LIKE 키워드를 사용하여 검색 텍스트를 기반으로 레코드를 필터링하는 MySQL 쿼리를 만들려고합니다.

예를 들어 사용자가 Illusion Softwares 를 검색하는 경우 Illusion 은 이름이고 Softwares 는 성이므로 쿼리는 FirstName, LastName 열을 검색해야합니다. 둘 다 연결하고 검색하십시오.

지금까지 시도했지만 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

내가 무엇을 놓치고 있습니까? 제발 도와주세요.

 

해결 방법

 

검색어는 다음과 같아야합니다.

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 

 

참조 페이지 https://stackoverflow.com/questions/32177797

 

 

반응형

댓글