左外連接
- 用在查詢塊的from短語中
- 又稱左連接,列出左邊所有元組,
A left join B on 條件表達式
中的on
決定了B表中符合條件表達式的數據才保留,不符合的右邊字段為null
- where短語的條件等到外連接結束后才使用,對外連接結果進行過濾
例子:
create table t1(c1 int primary key, c2 int);
create table t2(cc1 int primary key, cc2 int);
insert into t1 values (1,1),(2,2),(5,5);
insert into t2 values (2,2),(3,3),(4,4);
select * from t1 left join t2 on t1.c2=t2.cc2;
結果:
c1 c2 cc1 cc2 2 2 2 2 1 1 null null 5 5 null null
右外連接
同左外連接,只不過是列出右邊所有元組,又稱右連接
全外連接
左右表的所有元組均列出(且各只出現一次),不符合on
表達式的字段為null