chrizonline
chrizonline

Reputation: 4979

MySQL - DELETE FROM with subquery

im trying to execute this query but i'm getting error #1064.

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

But the following statement works

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

Upvotes: 0

Views: 58

Answers (1)

chrizonline
chrizonline

Reputation: 4979

Here is the answer:

to use a delete query with subquery which has a where condition, do the following:

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

Upvotes: 2

Related Questions