DELETE with JOIN
DELETE with JOIN is a SQL statement in the DML Statements category. Deletes rows from one table based on a join condition with another table. The syntax is DELETE t1 FROM table1 t1 JOIN table2 t2 ON t1.id = t2.id WHERE condition;. It returns rows deleted. A typical example: DELETE o FROM orders o JOIN customers c ON o.customer_id = c.id WHERE c.status = 'inactive'; -- Delete orders from inactive customers (MySQL syntax) -- PostgreSQL syntax: DELETE FROM orders o USING customers c WHERE o.customer_id = c.id AND c.status = 'inactive'; A close relative is INSERT INTO, which inserts new rows into a table. A close relative is UPDATE, which modifies existing rows in a table. Always use WHERE to avoid updating all rows. A close relative is DELETE, which removes rows from a table. Always use WHERE to avoid deleting all rows. More about this category: Data Manipulation Language — INSERT, UPDATE, DELETE, REPLACE, MERGE.