假设 A B 两个表 都有字段 id,要求查出A B两个表id的并集,并且去重,A B两个表本身id也可能有重复
select distinct t.id from (
select id from A
UNION ALL
select id from B
)t
select distinct a.id from A a,B b where a.id=b.id
select 字段1,字段2,字段3 from (
select A.字段1,A.字段2,A.字段3 from A
union all
select B.字段1,B.字段2,B.字段3 from A
) as tmp group by 字段1,字段2,字段3
select distinct a.id
from
(select id from A
union all
select id from B
)a