For multi-table deletes,
For the first multiple-table syntax, only matching rows from the tables listed before the
FROMclause are deleted. the second multiple-table syntax, only matching rows from the tables listed in theFROMclause (before theUSINGclause) are deleted.
DELETE t1, t2 FROM t1 INNER JOIN t2 INNER JOIN t3
WHERE t1.id=t2.id AND t2.id=t3.id;
Or:
DELETE FROM t1, t2 USING t1 INNER JOIN t2 INNER JOIN t3
WHERE t1.id=t2.id AND t2.id=t3.id;
And for LEFT JOIN, you should use something like
DELETE t1 FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE t2.id IS NULL;
No comments:
Post a Comment