Which fix removes the bug?
SELECT u.name, o.id FROM users u LEFT JOIN orders o ON o.user_id = u.id WHERE o.status = 'paid'; -- users with no paid order vanish
- Move the status test into
ON - Use a
RIGHT JOINfor orders - Add
GROUP BY u.nameat the end - Write
o.status IS 'paid'instead
For unmatched users o.status is NULL, so the WHERE drops them and the LEFT JOIN acts like an inner join.
Play Problem Solving ▸