Back to the Catalog
sql
joins
null
aggregation
debugging

SQL Query Detective

42 questions

Work out what each query returns and find the bug when it returns the wrong result. The quiz covers joins, fan-out, NULL, aggregation, and misleading filters. Unless stated otherwise, assume standard SQL behavior. Without ORDER BY, row order does not matter.

Questions

  1. Not answered. How many rows does this inner join return?
  2. Not answered. Which customer names survive this query?
  3. Not answered. What rows does moving the paid filter into ON produce?
  4. Not answered. What are the counts for customers with no orders?
  5. Not answered. What total does the query report after accidental fan-out?
  6. Not answered. Which approaches safely compute both item and payment totals per order?
  7. Not answered. What does NULL = NULL evaluate to in a SQL predicate?
  8. Not answered. Which standard SQL predicate considers two NULL values equal?
  9. Not answered. Which values does this NOT IN query return?
  10. Not answered. Which values does the NOT EXISTS anti-join return?
  11. Not answered. How many rows satisfy rating <> 5?
  12. Not answered. Which rows satisfy COALESCE(discount, 0) = 0?
  13. Not answered. What does SUM(amount) return when no rows qualify?
  14. Not answered. What does COUNT(amount) return when no rows qualify?
  15. Not answered. What is AVG(score) for scores 10, 20, and NULL?
  16. Not answered. What is COUNT(DISTINCT category) for A, A, B, and NULL?
  17. Not answered. How many groups does GROUP BY region form?
  18. Not answered. Which customers does this query find?
  19. Not answered. Why does this query omit departments with no sales since 2026 began?
  20. Not answered. Which clause should filter groups whose total sales exceed 1,000?
  21. Not answered. What defect causes the duplicated matches?
  22. Not answered. Which predicate produces each unordered employee pair exactly once?
  23. Not answered. How many rows result from joining students through enrollments?
  24. Not answered. What should you check when a many-to-one join doubles some sales?
  25. Not answered. Why is SELECT DISTINCT a risky repair for an unexpectedly duplicating join?
  26. Not answered. Which rows can match because of missing parentheses?
  27. Not answered. How many rows does the full outer join return?
  28. Not answered. How many rows do UNION ALL and UNION return?
  29. Not answered. How many rows does a cross join produce?
  30. Not answered. Why do authors without books disappear from this join chain?
  31. Not answered. Does a NULL join value match another NULL join value?
  32. Not answered. Why does a window total repeat an inflated value after a join?
  33. Not answered. What is guaranteed by SELECT id FROM tasks LIMIT 1 without ORDER BY?
  34. Not answered. Which 2026 rows can an inclusive BETWEEN filter accidentally omit?
  35. Not answered. Why does this expression count every row?
  36. Not answered. What does SUM(CASE WHEN paid THEN amount END) return when no row is paid?
  37. Not answered. When is LEFT JOIN ... WHERE right.key IS NULL a reliable anti-join?
  38. Not answered. What happens when a left-table filter is placed inside the ON clause?
  39. Not answered. What is wrong with grouping by both customer and order when one row per customer is required?
  40. Not answered. Does a group containing only NULL scores pass HAVING AVG(score) >= 0?
  41. Not answered. Which checks help find where unexpected fan-out begins?
  42. Not answered. Which rewrite preserves all accounts while counting only successful logins?