现在有两张表。test1(aa number,bb number),test2(aa number,bb number),
test1 表内容:     test2 表内容:
aa  bb                  aa    bb
1   2                   1      2
1   2                   1      4
1   3                   
要把test1中与test2中不相同的记录删除,test1中保留下与test2相同的记录,也就是test1中保留下两条aa=1,bb=2的记录。思路是怎样?越简单越好。急!大家多多帮忙!

解决方案 »

  1.   


    SQL> select * from test1;
     
            AA         BB
    ---------- ----------
             1          2
             1          2
             1          3
     
    SQL> select * from test2;
     
            AA         BB
    ---------- ----------
             1          2
             1          4SQL> delete test1 a
      2  where not exists(
      3        select 1
      4        from test2 b
      5        where a.aa=b.aa
      6          and a.bb=b.bb)
      7  /
     
    1 row deleted
     
    SQL> commit;
     
    Commit complete
     
    SQL> select * from test1;
     
            AA         BB
    ---------- ----------
             1          2
             1          2