表的內連線 外連線(左連線與右連線)

2021-07-24 11:24:45 字數 1064 閱讀 7132

.內連線:利用內連線可獲取兩表的公共部分的記錄

語句如下:select * from a join b on a.aid=b.bid;

.外連線:外連線分為兩種,一種是左連線(left join)和右連線(right join)

(1)左連線(left join):公共部分

語句如下:select * from a left join b on a.aid=b.bid;

(2)右連線(right join):

語句如下:select * from a right join b on a.aid=b.bnameid

在oracle

的sql語句常用的連線有內連線(inner join),外連線(outer join)等,內連線又包括等值連線,非等值連線,自連線;而外連線又分為左連線和右連線。其中預設的是內連線的等值連線。

內連線:innerjoin 表名 on 鍊錶條件

外連線: left / right outer join 表名 on 鍊錶條件

區別:內連線只顯示公共的資料,外連線一般是統計查詢適用,以某張表為基準

聯合查詢:union 將倆個查詢結果合併成乙個返回

子查詢:查詢語句中又巢狀了乙個查詢語句(條件).例如:查詢參加考試的學生資訊

內連線:利用內連線(等值)就可獲取公共部分c,圖中的資料集c.

select * from a inner join b on a.aid=b.bid;等價於select * from a,b where a.aid=b.bid 圖中c的部分

外連線:分為左外連線(left join)與右外連線(right join)

左外連線:select * from a,b where a.aid=b.bid(+);等價於select * from a left outer joinb on a.id=b.id圖中a+c的部分

右外連線:select * from a,b where a.aid(+)=b.bid;等價於select * from aright outer joinb on a.id=b.id圖中b+c的部分

左連線與右連線,外連線與內連線

左 left join select form tab1 left join tab2 on user id tab2.user id where tab1.user id 4 意思 就是讓tab1裡的user id為4的所有friend id當作tab2裡的user id,在tab2裡查詢符合的資...

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

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

SQL 內連線,外連線(左外連線 右外連線)

參考整理筆記 關鍵字 inner join on 語句 select from a table a inner join b table bon a.a id b.b id 執行結果 說明 組合兩個表中的記錄,返回關聯字段相符的記錄,也就是返回兩個表的交集 陰影 部分。關鍵字 left join o...