1.求并集
select
a.*
from table_a as a
union all
select
a.*
from table_b as b
使用 union或者union all,两个表的列数和列名顺序要相同
去重
select
a.*
from table_a as a
union
select
a.*
from table_b as b
2.求差集
select
a.*
from table_a as a
left join table_b as b
on a.id = b.id
where b.id is null
3.求交集
select
a.*
from table_a as a
inner join
select * from table_b as b
on a.id = b.id
或者
select
a.*
from table_a a
where not exsist(
select 1 from table_b b where a.id = b.id
)