mysql對資料庫多個字段同時進行模糊查詢

2021-09-02 12:13:38 字數 1134 閱讀 3955

select concat_ws(',',loginname,real_name,null )  from user_fore where concat(loginname,real_name) like '%1%' 

參考** 

mysql可以對資料庫多個字段同時進行模糊查詢,例如:資料庫設計中把姓名設計為兩個字段,乙個欄位為姓lastname,乙個欄位為名字firstname。當介面進行模糊搜尋時,mysql中有concat(...),concat_ws(...)兩個函式。

例子如下:

selcet * from t-user u where concat(u.lastname,u.firstname) like '%$lsp_name$%'

lastname 欄位是姓

firstname欄位是名字

當查詢欄位為null時,返回結果為null。與concat_ws(...)不同。

如果為多個字段同時進行查詢時,使用concat_ws(...).

select concat_ws(',','11','22','33');

select concat_ws(',','11','22','33',null);

都返回11,22,33

concat_ws() 代表 concat with separator,是concat()的特殊形式。第乙個引數是其它引數的分隔符。分隔符的位置放在要連線的兩個字串之間。分隔符可以是乙個字串,也可以是其它引數。

concat()可以連線乙個或者多個字串,concat_ws()可以新增分割符引數。

mysql同時查多個庫 資料庫同時查詢多個表

我在同乙個資料庫下建立了三個表 1,表 project projectid projectname 2,表 position positionid positionname 3,表 work workid workprojectid workpositionid workamount worktim...

Oracle語句中多個字段同時in

今天遇到乙個資料庫問題,a,b,c三表。需要從a表中查詢部分資料 select a.a1,a.a2 from a where 從b中刪除對應的資料,即刪除 select b.from b b,select a.a1,a.a2 from a where awhere a.a1 b.b1 and a.a...

oracle同時新增多個字段 案例

運算元據庫 oracle 10g 有時候有需要在oracle資料庫中新增多個欄位的需求,案例如下 alter table my workflow add state varchar2 2 default 0 not null,name varchar2 100 not null,age number...