Mysql Concat用LIKE搜索时两列 [英] Mysql Concat two columns while searching with LIKE
本文介绍了Mysql Concat用LIKE搜索时两列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试进行一个MySQL查询,在其中我使用LIKE关键字基于搜索文本过滤记录.
I am trying to make a MySQL query where I filter the records based on the search text using LIKE keyword.
例如,如果用户搜索Illusion Softwares
,其中Illusion
是名字,而Softwares
是姓氏,则查询应搜索FirstName,LastName和concat列并进行搜索.
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.
到目前为止,我已经尝试过了,但是不适用于CONCAT
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.
推荐答案
您的查询应该是这样
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
这篇关于Mysql Concat用LIKE搜索时两列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文