现有表A和表B,A中的ITEM字段和B中的CODE字段对应,现在我想查出两个表中ITEM 和CODE 没有对应值的数据,语句要怎么写呢?

解决方案 »

  1.   

     select * from A a where  not exists(select 1 from a where a.ITEM =b.CODE);
      

  2.   


    select a.* from a where item not in (select code from b)
    select a.* from a where not exists (select 1 from b code = a.item)select b.* from b where code not in (select item from a)
    select b.* from b where not exists (select 1 from a item = b.code)
      

  3.   


    select a.* from a where not exists (select 1 from b b.code= a.item)
    select b.* from b where not exists (select 1 from a a.item = b.code);select a.* from a where not exists (select 1 from b b.code= a.item)
    union all
    select b.* from b where not exists (select 1 from a a.item = b.code);
      

  4.   

    select a.* from a where not exists (select 1 from b b.code= a.item) 
    union all 
    select b.* from b where not exists (select 1 from a a.item = b.code); 这个固然可以,但是可能会影响性能,找找oracle中类似连接用法,会提高性能很多。