數據庫中內連接、外連接、全連接 內連接:把兩個表中數據對應的數據查出來 外連接:以某個表為基礎把對應數據查出來(全連接是以多個表為基礎) student表 no name 1 a 2 b 3 c 4 d grade表 no grade 1 90 2 98 3 95 www.2cto.com 內連接 inner join(查找條
數據庫中內連接、外連接、全連接
內連接:把兩個表中數據對應的數據查出來
外連接:以某個表為基礎把對應數據查出來(全連接是以多個表為基礎)
student表
no name
1 a
2 b
3 c
4 d
grade表
no grade
1 90
2 98
3 95
www.2cto.com
內連接 inner join(查找條件中對應的數據,no4沒有數據不列出來)
語法:select * from student inner join grade on student.no = grade.no
結果
student.no name grade.no grade
1 a 1 90
2 b 2 98
3 c 3 95
左連接(左表中所有數據,右表中對應數據,即左邊一定有數據,右邊不一定有)
語法:select * from student left join grade on student.no = grade.no
結果:
student.no name grade.no grade
1 a 1 90
2 b 2 98
3 c 3 95
4 d
右連接(右表中所有數據,左表中對應數據,即右邊一定有,左邊不一定有)
語法:select * from student right join grade on student.no = grade.no
結果:
student.no name grade.no grade
1 a 1 90
2 b 2 98
3 c 3 95
全外連接(表中數據=內連接+左邊缺失數據+右邊缺失數據)
www.2cto.com
語法:select * from student full join grade on student.no = grade.no
結果:
no name grade
1 a 90
2 b 98
3 c 95
4 d
1 a 90
2 b 98
3 c 95
交叉連接 (沒有where字句時結果為笛卡爾積) 一般不用。
注:access 中不能直接使用full join ,需要使用union all 將左連接和右連接合并后才可以
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com