MySQL - 使用子查询DELETE FROM

时间:2014-12-06 06:31:17

标签: mysql

我试图执行此查询,但我收到错误#1064。

delete from tableABC WHERE ID in (select ID from `TABLEXYZ` where `qty` = 0);

但以下声明有效

  

从tableABC WHERE ID中选择*(从TABLEXYZ中选择ID在哪里   qty = 0);

1 个答案:

答案 0 :(得分:2)

以下是答案:

要使用具有where条件的子查询的删除查询,请执行以下操作:

DELETE a FROM `tableABC` AS a JOIN (SELECT ID FROM `tableXYZ` WHERE `qty`=0) as b on b.ID = a.ID