是不是这样
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)

解决方案 »

  1.   

    --感觉好像是这个意思
    select a1 from tab1 
    union 
    select a2 from tab1
      

  2.   

    --这样看的比较清楚
    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)
      

  3.   

    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)
      

  4.   

    select distinct(A1) from Tab1 where not exists(select distinct(A2) from Tab1 where A1 = A2) 自己解决了. 灵感来自  zjcxc(邹建) pbsql(风云) 以前的帖子,谢谢大家
      

  5.   

    davorsuker39(大狐狸) 的方法不对,其他的还没来的急试.
      

  6.   

    pbsql(风云)  zjcxc(邹建) 两位可能没理解我的意思.
      

  7.   

    pbsql(风云)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)这种方法思路是正确的可是 总感觉少了点什么? 很难说清.
    我想把 A1 和 A2 比较 返回 所有不同的 值. 上面那条SQL语句绝对做不到这一点.
      

  8.   

    select a1 
    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
      

  9.   

    select distinct(a1) from tab1
    union 
    select distinct(a2) from tab1这个结果是我想要的 谢谢大家.结贴.