$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · hard · #237

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
  1. Move the status test into ON
  2. Use a RIGHT JOIN for orders
  3. Add GROUP BY u.name at the end
  4. 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 ▸