Mysql學習筆記(2)- 常見通用JOIN查詢
阿新 • • 發佈:2018-12-11
- 左連線 left join (A所有,包含與B的交集)
select * from A
left join B on A.key = B.key
-- 結果 = A所有+AB交集
- 右連線 right join (B所有,包含與A的交集)
select * from A
right join B on A.key = B.key
-- 結果 = B所有+AB交集
- 內連線(交集): inner join (A和B的共有部分,即交集)
select * from A
inner join B on A.key = B.key
-- 結果 = AB交集
- A獨有
select * from A
left join B on A.key = B.key
where B.key is null
- B獨有
select * from A
right join B on A.key = B.key
where A.key is null
- 外連線 (AB並集)
select * from a
full outer join b on a.key = b.key
- 外連線 (AB差集)
select * from a
full outer join b on a.key = b.key
where a.key is null or b.key is null