EasySubqueries & EXISTS
NOT EXISTS: customers who never ordered
The query
SQL
SELECT name, email, joined_at
FROM customers c
WHERE NOT EXISTS (
SELECT 1
FROM orders o
WHERE o.cust_id = c.cust_id
)
ORDER BY joined_at DESC;Note
“NOT EXISTS is usually faster than NOT IN when subquery result may include NULLs.