有兩個表Table1和Table2,分別為:
Table1(A,B,C,D,E,F,G,H,I,J,K)
Table2(X,Y,Z)。
刪除table1中記錄,刪除的記錄需要符合如下要求:
字段B等于字段X的值,字段C等于字段Y的值,字段D等于字段Z的值。其中A為table1的主鍵。
怎么寫Sql語句?

解决方案 »

  1.   


    delete table1 from table1 t1 inner join table2 t2 on t1.B=t2.X and t1.C=t2.Y and t1.D=t2.Z
      

  2.   


    delete table1 from table1,table2 
    where table1.B=table2.X and table1.C=table2.Y and table1.D=table2.Z
      

  3.   

    delete  from table1 a
    join table2 b
    on a.b=b.x and a.c=b.y and a.d=b.z
      

  4.   

    delete  table1 from table1 a
    where exists(select 1 from table2 b
     where a.b=b.x and a.c=b.y and a.d=b.z)
      

  5.   

    delete Table1 from Table1 a join Table2 b on a.b=b.x and a.c=b.y and a.d=b.z