表 TEST1, TEST2
TEST1与TEST2字段相同,字段内容如下:
A  varchar2(10)
B  varchar2(10)
C  varchar2(10)现在想删除TEST2表中的数据
条件是TEST1.A=TEST2.A
能用一条SQL语句实现吗

解决方案 »

  1.   

    delete from test2 where a in (select a from test1)
      

  2.   

    引用kkcolcol(kkcolcol) 的思想,你的要求
    >这只是我简单描述,但实际上条件有好几个这样好了:delete 
    from test2 
    where a||条件2字段||条件3字段... in (select a||条件2字段||条件3字段... from test1)
      

  3.   

    delect from TEST2 where (条件1,条件2,条件3)=(select 条件1,条件2,条件3 from TEST1)
      

  4.   

    这样吧:
    delete from test2 t2 where a in (select a from test1 t1 and t1.条件1 = t2.条件1 and t1.条件2 = t2.条件2 ...)
      

  5.   

    这样写在数据量比较大时效率高些
    delete from test2 t2 where 只包含test2中字段的条件集 and exists (select 1 from test1 t1 and t1.条件1 = t2.条件1 and t1.条件2 = t2.条件2 ...)
      

  6.   

    用一条语句:
    delete from Test2 where exists (select 1 from Test1 where 两表关联条件);但Test2数据多的话上面的效率可能较低,不如这样做:
    create table tmpTable as 
        select * from Test2 
        where not exists (select 1 from Test1 where 两表关联条件);truncate table Test2;insert into Test2
    select * from tmpTable;drop table tmpTable;