DELETE using a join

Remove rows from one table based on another. Run it as a SELECT first.

SQL · DELETE using a joinIntermediate
-- preview
SELECT i.* FROM order_items i JOIN orders o ON o.id = i.order_id WHERE o.status = 'cancelled';

DELETE i
FROM order_items i
JOIN orders o ON o.id = i.order_id
WHERE o.status = 'pending';
deletejoincleanup