資料庫內連線 左連線 右連線 全連線

2021-07-27 10:26:57 字數 1375 閱讀 7157

1.內連線我們通常用的連線,表表連線只顯示交集資料。

2.外連線分左外連線 table1 left outer join on table2、右外連線table1 right outer join on table2 、全連線table1 full outer join on table2。

2.1左外連線就是在等值連線的基礎上加上主表中的未匹配資料。

2.2右外連線是在等值連線的基礎上加上被連線表的不匹配資料。

2.3全外連線是在等值連線的基礎上將左表和右表的未匹配資料都加上。

內連線:把兩個表中資料對應的資料查出來

外連線:以某個表為基礎把對應資料查出來(全連線是以多個表為基礎)

student表

no name

1 a2 b

3 c4 d

grade表

no grade

1 90

2 98

3 95

內連線 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

左連線 left join(左表中所有資料,右表中對應資料)

語法: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右連線 right join(右表中所有資料,左表中對應資料)

語法: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

全連線 full join

語法:select * from student full join grade on student.no = grade.no

結果:no name grade

1 a 90

2 b 98

3 c 95

4 d1 a 90

2 b 98

3 c 95

注:access 中不能直接使用full join ,需要使用union all 將左連線和右連線合併後才可以

資料庫內連線 外連線(左連線 右連線 全連線)

內連線 把兩個表中資料對應的資料查出來 外連線 以某個表為基礎把對應資料查出來 全連線是以多個表為基礎 student表 no name 1 a 2 b 3 c 4 d grade表 no grade 1 90 2 98 3 95 內連線 inner join 查詢條件中對應的資料,no4沒有資料不...

資料庫內連線 左連線 右連線

1.內連線我們通常用的連線,表表連線只顯示交集資料 2.外連線分左外連線 table1 left outer join on table2 和右外連線table1 right outer join on table2 和全連線 table1 full outer join on table2 2.1...

資料庫 內連線 左外連線 右外連線 全外連線

內連線中,只有滿足連線條件的元組才能作為結果輸出,即當任乙個表中為null則不會輸出。sql 語句 123 select first.cno,second.cpno from course first,course second where first.cpno second.cno 如果在查詢時需...