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这篇文章里有道题,看完可以实践一下。