sql集合運算的關鍵字
sql中,對於集合的計算有:並集、差集、交集。
並集:union,union all
差集:EXISTS,not in,except
交集:InterSect
但是吧,不是每個數據庫都支持上面所有的,而且關鍵字還不一樣。就像oracle,差集用minus 。emmm…好難受。
join也可以實現
實現這種情況,inner join就可以了。
實現這種情況,left join就可以了。
實現這種情況,right join就可以了。
實現這種情況:
select *
from a left join b
on a.id = b.id
where b.id is null
實現這種情況:
select *
from a right join b
on a.id = b.id
where a.id is null
https://blog.csdn.net/weixin_42845682/article/details/105412597這篇文章裏有道題,看完可以實踐一下。