sql連線查詢

2022-03-08 18:20:39 字數 553 閱讀 2564

1.內鏈結(inner join on)

結果集是返回兩個表中符合條件的資料,而捨棄不符合條件的語句

select * from table1 inner join table2 on table1_id=table2_id where age>20

2.外連線

(1)左外連線(left outer join/left join)

返回所有的匹配行並從關鍵字join左邊表中返回所有不匹配行,右邊表中沒有的用null填充

(2)左外連線(right outer join/right join)

返回所有的匹配行並從關鍵字join右邊表中返回所有不匹配行,左邊表中沒有的用null填充

(3)完整外部連線(full outer join/full join)

返回兩個表中所有匹配行和不匹配行

3.自身連線

指表與自身連線 必須為每個連線表取乙個別名

select * from student s1 inner join student s2 on s1.id=s2.id where s2.xh='063823031'

SQL 連線查詢

連線查詢是指乙個查詢同時涉及到兩個及以上的表。包括 等值連線,自然連線,非等值連線,自身連線,外連線,復合查詢.等.color red size large 1.等值連線 於非等值連線 size color 查詢每個學生及選課的情況 select student.sc.from student,sc...

sql連線查詢

sql連線查詢的連線查詢分為交叉連線 內連線 外連線。以下面兩張表為例演示連線查詢。a表 b表 分為左連線 右連線 完全外連線 左連線 left join 或left outer join select from a left outer join b on a.aid b.bid返回結果 返回a表...

SQL連線查詢

筆記區 多表連線查詢 1,等值連線 select from table1,table2 where table1.t1no table2.t2no 2,非等值 笛卡爾積 特點 查詢個數為乘積 作用 模擬大量資料 交叉連線 自連線內連線 把符合條件的查出來 以上都是內查詢 外連線 可以把不存在員工的部...