Back to the catalog

SQL query detective

42 questions

Read each query, predict what it returns, and spot the bug when the result is wrong. You'll work through joins, fan-out, NULL, aggregation, and filters that don't do what they seem to. Assume standard SQL unless a Question says otherwise. Without ORDER BY, row order doesn't matter.

Questions

  1. Not answered. How many rows does this inner join return?
  2. Not answered. Which customer names does this query return?
  3. Not answered. What does the query return with the paid filter moved into ON?
  4. Not answered. What are the counts for a customer with no orders?
  5. Not answered. What item_total does this query report?
  6. Not answered. Which approaches give correct 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 treats two NULLs as equal?
  9. Not answered. Which values does this NOT IN query return?
  10. Not answered. Which values does this NOT EXISTS query 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 leave out departments with no sales since the start of 2026?
  20. Not answered. Which clause keeps only groups with total sales over 1,000?
  21. Not answered. What causes the duplicate matches?
  22. Not answered. Which predicate produces each unordered employee pair exactly once?
  23. Not answered. How many rows does joining students through enrollments return?
  24. Not answered. A many-to-one join doubles some sales. What should you check?
  25. Not answered. Why is SELECT DISTINCT a risky fix for a join that duplicates rows?
  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 key match another NULL?
  32. Not answered. Why does this window total show an inflated value?
  33. Not answered. What does SELECT id FROM tasks LIMIT 1 guarantee without ORDER BY?
  34. Not answered. Which 2026 rows can this inclusive BETWEEN filter miss?
  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 you put a left-table filter in ON?
  39. Not answered. What's wrong with this query if you need one row per customer?
  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 query keeps every account but counts only successful logins?