union怎么过滤带有自定义字段的数据

select ‘1’,name,age from a union select ‘2’,name,age from b
怎么去除b中重复的数据,因为有自定义字段,所以全都读出来了,不能使用条件,如: 
select ‘1’,name,age from a union select ‘2’,name,age from b where not exists (select 1 from a where a.name=b.name and a.age=b.age)

select ‘1’,name,age from a union select DISTINCT ‘2’,name,age from b

 

你先distinct b表,然后再union起来?

你这不是自己写出来了嘛,你写的那个就是最优的了,也可以关联,但是道理一样。