zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

mysql concat_ws 与 concat 多字段模糊匹配应用

mysql应用 匹配 模糊 CONCAT WS 多字段
2023-09-27 14:26:24 时间

有时我们希望在表中多个字段检索是否有我们给出的关键字,我们可以使用 concat_ws 和 concat 连接需要检索的字段,如:

select * from userInfo where concat(`user_name`,`email`) like '%root%';

或者:

select * from userInfo where concat_ws(',',`user_name`,`email`) like '%root%';

  CONCAT_WS() 代表 CONCAT With Separator ,是CONCAT()的特殊形式。但是要注意一点,如果连接的字段中有为空,那么concat会返回空串,concat_ws则不会返回空串