SQL 的各種 join 用法

2021-09-13 00:15:37 字數 1751 閱讀 2035

下圖展示了 left join、right join、inner join、outer join 相關的 7 種用法。

具體分解如下:

1、inner join(內連線)

2、left join(左連線)

select from table_a a

left join table_b b

on a.key = b.key

3、right join(右連線)

select from table_a a

right join table_b b

on a.key = b.key

4、outer join(外連線)

select from table_a a

full outer join table_b b

on a.key = b.key

5、left join excluding inner join(左連線-內連線)

select from table_a a

left join table_b b

on a.key = b.key

where b.key is null

6.right join excluding inner join(右連線-內連線)

select from table_a a

right join table_b b

on a.key = b.key

where a.key is null

7、outer join excluding inner join(外連線-內連線)

select from table_a a

full outer join table_b b

on a.key = b.key

where a.key is null or b.key is null

各種JOIN 用法

declare ta table id int,va varchar 10 declare tb table id int,vb varchar 10 insert into ta select 1,aa insert into ta select 2,bc insert into ta selec...

SQL 各種 join 的區別

參考 test ora1 sql select from a 編號 姓名 1000 張三 2000 李四 3000 王五 test ora1 sql select from b 編號 商品 1000 電視機 2000 錄影機 4000 自行車 test ora1 sql select a.b.fro...

sql的各種join連線

1 select from tablea inner join tableb 2 on tablea.name tableb.name 3id name id name 4 51 pirate 2 pirate 63 ninja 4 ninja78 9inner join 10產生的結果集中,是a和...