a表name age
小明 22
小王  21b表name age
小明 22现在我要查出a表存在b表不存在的记录,即  name age
小王  21怎么做?
注:能不用in就不用in,因为他有点慢。

解决方案 »

  1.   

    select * from a where not exists (select 1 from b where b.name=a.name and b.age=a.age);
      

  2.   

    with a as(
    select '小明' name,22 age from dual
    union all
    select '小王',21 from dual),
    b as(
    select '小明' name,22 age from dual)
    select * from a
    where not exists(select 1 from b where b.name=a.name and b.age=a.age)NAME        AGE
    ---- ----------
    小王         21
      

  3.   


    select * from a where not exists (select 1 from b where b.name=a.name and b.age=a.age);
      

  4.   

    select * from a
    minus
    select * from b 
      

  5.   

    select * from A minus select * from B
      

  6.   

    用minus啦,这个是取数据集的减集
      

  7.   

    求交集就可以了,oracle有函数给你用滴~~minus