-- ALWAYS preview with SELECT first — DELETE is one-way
SELECT o.*
FROM orders o
JOIN users u ON u.id = o.user_id
WHERE u.status = 'banned';
-- PostgreSQL — DELETE ... USING
DELETE FROM orders o
USING users u
WHERE u.id = o.user_id
AND u.status = 'banned';
-- MySQL — DELETE table FROM table JOIN table
DELETE o
FROM orders o
JOIN users u ON u.id = o.user_id
WHERE u.status = 'banned';
-- Delete with subquery (works everywhere)
DELETE FROM orders
WHERE user_id IN (SELECT id FROM users WHERE status = 'banned');
-- Limit how many rows you delete (MySQL has DELETE ... LIMIT N)
DELETE FROM events WHERE created_at < NOW() - INTERVAL 90 DAY LIMIT 10000;
Create a free account and build your private vault. Share publicly whenever you want.