mysql 中怎麼查詢關鍵字,mysql 中怎麼查詢一個關鍵字

2022-02-15 11:29:22 字數 3301 閱讀 1686

1樓:貳兩毛尖

select * from 'user' where 欄位1 like "%關鍵字%" or 欄位2 like "%關鍵字%" or 欄位n like "%關鍵字%"

欄位1到欄位n用 or條件,只能這樣

2樓:匿名使用者

假設你要查詢user表裡面name欄位下得帶有「傑」字的使用者sql語句:

select * from 'user' where 'name' like "%傑%" order by id desc

%傑%表示模糊查詢,只有帶有傑的 都會列出來。

mysql資料庫如何搜尋關鍵詞

3樓:du瓶邪

辦法如下:

select * from table1 where concat(`欄位`,`欄位`,`欄位` ) like '%關鍵字%' union

select * from table2 where concat(`欄位`,`欄位`,`欄位` ) like '%關鍵字%' union

select * from table3 where concat(`欄位`,`欄位`,`欄位` ) like '%關鍵字%' union

select * from table4 where concat(`欄位`,`欄位`,`欄位` ) like '%關鍵字%' union

select * from table5 where concat(`欄位`,`欄位`,`欄位` ) like '%關鍵字%'

前提是查詢出來的欄位個數要一樣,型別要對應好,至於如何得到正確且符合你需要的sql就要在程式類中處理了。

4樓:

select * from table1 where 列名1 like 『%77%'

mysql如何查詢和欄位中某個字或詞相同的關鍵字?

5樓:園園

用模糊查詢,下述為**:

sql模糊查詢的語法為

「select column from table where column like ';pattern';」。

sql提供了四種匹配模式:

1. % 表示任意0個或多個字元。如下語句:

select * from user where name like ';%三%';

將會把name為「張三」,「三腳貓」,「唐三藏」等等有「三」的全找出來;

2. _ 表示任意單個字元。語句:

select * from user where name like ';_三_';

只找出「唐三藏」這樣name為三個字且中間一個字是「三」的;

select * from user where name like ';三__';

只找出「三腳貓」這樣name為三個字且第一個字是「三」的;

3. [ ] 表示括號內所列字元中的一個(類似與正規表示式)。語句:

select * from user where name like ';[張李王]三';

將找出「張三」、「李三」、「王三」(而不是「張李王三」);

如 [ ] 內有一系列字元(01234、abcde之類的)則可略寫為「0-4」、「a-e」

select * from user where name like ';老[1-9]';

將找出「老1」、「老2」、……、「老9」;

如要找「-」字元請將其放在首位:';張三[-1-9]';

4. [^ ] 表示不在括號所列之內的單個字元。語句:

select * from user where name like ';[^張李王]三';

將找出不姓「張」、「李」、「王」的「趙三」、「孫三」等;

select * from user where name like ';老[^1-4]';

將排除「老1」到「老4」尋找「老5」、「老6」、……、「老9」。

!最後是重點!

由於萬用字元的緣故,導致我們查詢特殊字元「%」、「_」、「[」、「';」的語句無法正常實現,而把特殊字元用「[ ]」括起便可正常查詢。據此我們寫出以下函式:

function sqlencode(str)

str=replace(str,"';","';';")

str=replace(str,"[","[") ';此句一定要在最先

str=replace(str,"_","[_]")

str=replace(str,"%","[%]")

sqlencode=str

end function

6樓:塞納河邊小石頭

一句話搞定

$key = '勝利';

select * from user where username like "%$key%";

mysql資料庫 怎麼在多個表中 查詢一個關鍵詞 100

7樓:四字點評

如果五張表都有關聯,就整合到一個sql語句

如果沒有的話,就只能分別讀取

最後將他陳入一個陣列,返回結果

8樓:匿名使用者

select * from table1 where concat(`欄位`,`欄位`,`欄位` ) like '%關鍵字%' union

select * from table2 where concat(`欄位`,`欄位`,`欄位` ) like '%關鍵字%' union

select * from table3 where concat(`欄位`,`欄位`,`欄位` ) like '%關鍵字%' union

select * from table4 where concat(`欄位`,`欄位`,`欄位` ) like '%關鍵字%' union

select * from table5 where concat(`欄位`,`欄位`,`欄位` ) like '%關鍵字%'

前提是查詢出來的欄位個數要一樣,型別要對應好,至於如何得到正確且符合你需要的sql就要在程式類中處理了

9樓:sxy小瑜

你先把這幾個表關聯起來,然後用檢視的方法呼叫就ok

10樓:匿名使用者

left join 可以嗎

mysql怎麼一個關鍵字模糊查詢兩個欄位

11樓:匿名使用者

select * from sys_food where concat(foodname,factoryname) like '%白%'

mysql連表查詢只要多表中的最後一條記錄

select a.name,max b.log time from 表 bai1 as a,表2 as b where a.id b.user id group by a.name 根據du 您最新的需求 select a.name,b.log time from 表1 as a,表2 as b w...

sql查詢兩個欄位相同的記錄,查詢一個表中的兩個欄位值相同的資料

難道是下面 的這種?select from linkuser where lname username 意思是去除重複的?select from linkuser awhere exists select 1 from select min id lname from linkuser group ...

sql語句怎麼從一張表中查詢資料插入到另一張表中

首先,查詢出來的資料 式要與待插入的另一張表的格式相同,欄位型別相同。insert into b in d 另一張表所在文件 select from a where 上面就是把從a表中查詢到的資料插入到另一個文件中的b表中。insert into 表a 列1,列2 select 列1,列2 from...