表结构是这样
a b
2 1
3 2
4 3
6 5如果b中的在a中存在就把b滤掉,最后应该就剩下 2 1,6 5。谢谢

解决方案 »

  1.   

    select a,b from table where b not in (select a from table)
      

  2.   


    原来是列比较啊:
    select a,b from tb t1 where not exists(select 1 from tb t2 where t2.a=t1.b )
      

  3.   


    SELECT * FROM TABLE A WHERE NOT EXISTS( select 1 from TABLE  where a=A.b  )
      

  4.   

    select * from tab where a not in (select b from tab) 
      

  5.   

    select * from tab where a not in (select b from tab) 
      

  6.   

    经过测试,结果完全正确:
    select test.a, test.b from testtable test 
    where test.b not in (
         select t1.a from testtable t1
    )
      

  7.   

    支持使用exists,效率比较高:
    select a,b from tb t1 where not exists(select 1 from tb t2 where t2.a=t1.b )
      

  8.   

    单个表的查询可以用自连接self join,把一个表当成两个表来看
      

  9.   

    exists比較快一點,樓上正解
    select a,b from tb t1 where not exists(select 1 from tb t2 where t2.a=t1.b )
      

  10.   

    select a,b from tb t1 where not exists(select 1 from tb t2 where t2.a=t1.b )
      

  11.   

    select * from tab where a not in (select b from tab)