內連線,左外連線,右外連線,全連線

2021-08-19 06:09:55 字數 1324 閱讀 4167

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

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

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

全連線語法: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 將左連線和右連線合併後才可以

MySQL內連線 左外連線 右外連線 全外連線

連線的優勢是減少了外來鍵的使用。內連線 最常見的等值連線,指連線結果僅包含符合連線條件的行,參與連線的兩個表都應該符合連線條件。inner join或join on condition 首先建立兩個表person和card,內容如下 select from card id cardname 1 ca...

SQL 左外連線,右外連線,全連線,內連線

例子1 a表 id name b表 id job parent id 1 張3 1 23 1 2 李四 2 34 2 3 王武 3 34 4 a.id同parent id 存在 關係內連線 select a.b.from a inner join b on a.id b.parent id 結果是 ...

內連線,外連線,左連線,右連線,全連線

連線是指將關聯式資料庫中的兩個表根據內容一定的條件連線成乙個表.內連線是最常用的鏈結,也叫等值鏈結,最常見的格式是 selecta.b.fromta as a tb as b wherea.id b.id 或者 selecta.b.fromtaasainnerjoin tbasb on a.id b...