MySQL DELETE JOIN

This quick reference introduces you a more flexible way to delete data from multiple tables by using INNER JOIN or LEFT JOIN clause in the DELETE statement.

MySQL DELETE JOIN with INNER JOIN Syntax

DELETE T1, T2
FROM T1
INNER JOIN T2 ON T1.key = T2.key
WHERE condition

MySQL DELETE JOIN with INNER JOIN Example

DELETE offices, employees
FROM offices
INNER JOIN employees
ON employees.officeCode = employees.officeCode
WHERE offices.officeCode = 5

MySQL DELETE JOIN with LEFT JOIN Example

DELETE T1
FROM T1
LEFT JOIN T2 ON T1.key = T2.key
WHERE T2.key IS NULL

No comments yet.

Leave a Reply

*