我想搜索三个字段:id,name和address。我希望我的搜索有点聪明。
订阅者表
id | firstname | lastname | address
N29-0001 | John | Doe | California
N29-0002 | Jonathan | Morson | Miami
到目前为止我的查询
select subscriberid, CONCAT(firstname," ",lastname) as fullname, address, city from subscriber where id like "%N29 Joh%" or CONCAT(firstname," ",lastname) like "%N29 Joh%" or address like "%N29 Joh%" or city like "%N29 Joh%"
我想查询是否输入 N29 Joh ,它会搜索John Doe。
答案 0 :(得分:1)
您可能需要全文索引。但是,如果您希望匹配任何单词并且不关心性能,则可以使用正则表达式:
select subscriberid, CONCAT(firstname, ' ', lastname) as fullname,
address, city
from subscriber
where subscriberid regexp 'N29|Joh' or
concat(firstname, ' ', lastname) like 'N29|Joh' or
address like 'N29|Joh' or
city like 'N29|Joh';