有兩個表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語句?
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語句?
delete table1 from table1 t1 inner join table2 t2 on t1.B=t2.X and t1.C=t2.Y and t1.D=t2.Z
delete table1 from table1,table2
where table1.B=table2.X and table1.C=table2.Y and table1.D=table2.Z
join table2 b
on a.b=b.x and a.c=b.y and a.d=b.z
where exists(select 1 from table2 b
where a.b=b.x and a.c=b.y and a.d=b.z)