是不是这样
select a1 from tab1 where a1 not in(select a2 from tab1)
union all
select a2 from tab1 where a2 not in(select a1 from tab1)
select a1 from tab1 where a1 not in(select a2 from tab1)
union all
select a2 from tab1 where a2 not in(select a1 from tab1)
select a1 from tab1
union
select a2 from tab1
select a1, null as a2 from tab1 where a1 not in(select a2 from tab1)
union all
select null as a1, a2 from tab1 where a2 not in(select a1 from tab1)
union all
select a2 from tab1 where a2 not in(select a1 from tab1)
union all
select a2 from tab1 where a2 not in(select a1 from tab1)这种方法思路是正确的可是 总感觉少了点什么? 很难说清.
我想把 A1 和 A2 比较 返回 所有不同的 值. 上面那条SQL语句绝对做不到这一点.
from tab1 a
where a1 not in(select a2 from tab1)
and (select count(*) from tab1 where a1=a.a1)=1
union all
select a2
from tab1 a
where a2 not in(select a1 from tab1)
and (select count(*) from tab1 where a2=a.a2)=1
union
select distinct(a2) from tab1这个结果是我想要的 谢谢大家.结贴.