1. 程式人生 > >mysql concat_ws 與 concat 多字段模糊匹配應用

mysql concat_ws 與 concat 多字段模糊匹配應用

class 一點 lec 應用 使用 tor pan pre 是否

有時我們希望在表中多個字段檢索是否有我們給出的關鍵字,我們可以使用 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則不會返回空串

mysql concat_ws 與 concat 多字段模糊匹配應用