Databases · Junior · Question 23 of 75
How do you find users who have no orders?
- 1
INNER JOIN orders o ON o.user_id = u.id WHERE o.id IS NULL - ✓Correct answer:
LEFT JOIN orders o ON o.user_id = u.id WHERE o.id IS NULL(orWHERE NOT EXISTS (...)) - 3
SELECT * FROM users WHERE orders = 0
Explanation
This is an 'anti-join'. NOT EXISTS expresses it directly and the planner handles both forms well.