①取合集
select id from
(
select id from A
UNION
select id from B
)ti
UNION会自动去重
②取交集
select id from
(
select id from A
UNION ALL
select id from B
)ti group ti.id having count(id)>1
UNION ALL 不会自动去重
或
select id from
(
select id from A
)ti
and id in (select id from B)
欢迎指正~