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