假设有表tableA、tableB,他们都有字段id和name

 

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

交集:INTERSECT (适用于两个结果集)

select a.id, a.name from tableA a
INTERSECT
select b.id, b.name from tableB b

 

差集:MINUS(适用于两个结果集)

select a.id, a.name from tableA a
MINUS
select b.id, b.name from tableB b

 

并集:UNION(适用于两个结果集)

-- UNION、UNION ALL能对两个或以上的结果集进行合并
-- 不包括重复行,进行默认排序
select a.id, a.name from tableA a
UNION
select b.id, b.name from tableB b

-- 包括重复行,不进行默认排序
select a.id, a.name from tableA a
UNION ALL
select b.id, b.name from tableB b
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄