有两个数据表,分别是(tbA [a1,a2]    tbB [b1,B2]),下面是具体数据tba
A1            A2
---------------------
211-09010001  70202100-043
211-09010001  70202100-042tbB
B1            B2
---------------------
211-09010001  70202100-040
211-09010001  70202100-042
211-09010001  70202100-043
用语句查出tbB中不存在于tbA的记录(按上面的数据应该只显示tbB的第一条记录.因为只有这一条不存在于tbA表中).

解决方案 »

  1.   

    select *
      from tbB b
     where not exists (select *
              from tbA a
             where a.a1 = b.b1
               and a.a2 = b.b2)
      

  2.   

    select B1,B2 from tbB
    minus
    select A1,A2 from TbA
      

  3.   

    试试这个 我还没试
    select * from tbB b where b.B1 not in(select a.A1 from tbA a where a.a1=b.b1) and b.b2 not in 
      (select a.a2 from tbA a where a.a2=b.b2)
      

  4.   

    select * from tbB b
    where not exists 
      (select * from tbA a
       where a.a1 = b.b1
         and a.a2 = b.b2)
      

  5.   

    select B1,B2 from tbB 
    minus 
    select A1,A2 from TbA
      

  6.   

    create table tba(a1 varchar2(20),a2 varchar2(20));
    insert into tba values('211-09010001','70202100-043');
    insert into tba values('211-09010001','70202100-042');create table tbb (b1 varchar2(20),b2 varchar2(20));
    insert into tbb values('211-09010001','70202100-040');
    insert into tbb values('211-09010001','70202100-042');
    insert into tbb values('211-09010001','70202100-043');
    commit;
    select *
      from tbB b
     where not exists (select *
              from tbA a
             where a.a1 = b.b1
               and a.a2 = b.b2)  select *
              from tbb
            minus
            select * from tba;
      

  7.   

    select * from tbb where (b1,b2) not in (select * from tba)
    实在不算高难度啊
      

  8.   


    顶一下,其实就是tbB与tbA的差集
      

  9.   

    这也叫高难度
    一个minus就解决了
      

  10.   

    用minus 取差集 select B1,B2 from tbB
    minus
    select A1,A2 from TbA 
    就这样