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

有时我们希望在表中多个字段检索是否有我们给出的关键字,我们可以使用 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则不会返回空串

原文地址:https://www.cnblogs.com/liang1101/p/8510023.html