删除两个表中满足条件的记录

问题描述 投票:-1回答:1
delete m1
from table_a m1
inner join table_a m2 on m1.etid = m2.etid and m1.id <> m2.id
where m1.gid = 198 and m1.etid != 339 and m1.etid != 15451... 

我具有上面的代码,它将删除不具有属于特定类型的etid的所有记录。

etid和它的内容类型存储在另一个名为table_b的表中,所以我需要更改以上查询,以便不会一一给出不会删除的etid号,所以我不得不说:删除满足上述查询条件的所有etid记录,但它们的类型也必须为材料。

如何更改以上查询?

mysql
1个回答
0
投票

您可以尝试:

delete m1
from table_a m1
inner join table_a m2 on m1.etid = m2.etid and m1.id <> m2.id
where m1.gid = 198 and m1.etid not in (SELECT etid FROM .....)

您必须填写.....您自己😁

© www.soinside.com 2019 - 2024. All rights reserved.