mysql 查詢好友語句 MySQL高階查詢語句

2021-10-17 06:04:55 字數 777 閱讀 8724

高階查詢:

一:多表連線

1.select info.code,info.name,nation.name from info,nation where info.nation = nation.code 查幾張表就就輸出幾張表,查那個條件就輸出那個條件 列的查詢

select * from info,nation 全部輸出4x4

2.join連線

select * from info join nation on info.nation = nation.code 篩選輸出資料

二:多表聯合

select * from info where code='p001'union select * from info where nation='n001' union 聯合 行的查詢

三:子查詢(無關子查詢)

select * from info where nation = (select code from nation where name='漢族') 兩個查詢 乙個查詢的結果當做另乙個查詢的條件 查乙個 =

select * from info where nation in (select code from nation where name='漢族' or name='苗族')

in(在裡面)not in (在不裡面)任意乙個都可以 作為兩個查詢結果的鏈結 查兩個in

select * from car a where a.oil

把外子查詢定義乙個a 裡面的表定義成b 外層表看油耗 裡層求油耗的平均值(每乙個資料都走一遍)

mysql 查詢語句

在pdo中有很多模式能用,在使用的時候在用 bindvalue 的時候 在select 中有in 的 語句無法實現,在傳入的時候 select from users where id in 1,2,3 當1,2,3 用 pdo param str 的時候,會出現這種情況 select from ue...

MySQL查詢語句

建立水果表 create table fruits f id char 10 not null,s id int notnull,f name char 255 not null,f price decimal 8,2 not null,primary key f id 插入資料 insert in...

MYSQL查詢語句

內連線 取的兩個表的 有能連線的字段 的交集,即欄位相同的。利用內連線可獲取兩表的公共部分的記錄。select st.sno,st.sname,st.s st.age,st.sdept,co.cname,sc.grade from student st,course co,score sc wher...