SQL Query Detective
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
- Not answered. How many rows does this inner join return?
- Not answered. Which customer names survive this query?
- Not answered. What rows does moving the paid filter into
ONproduce? - Not answered. What are the counts for customers with no orders?
- Not answered. What total does the query report after accidental fan-out?
- Not answered. Which approaches safely compute both item and payment totals per order?
- Not answered. What does
NULL = NULLevaluate to in a SQL predicate? - Not answered. Which standard SQL predicate considers two NULL values equal?
- Not answered. Which values does this
NOT INquery return? - Not answered. Which values does the
NOT EXISTSanti-join return? - Not answered. How many rows satisfy
rating <> 5? - Not answered. Which rows satisfy
COALESCE(discount, 0) = 0? - Not answered. What does
SUM(amount)return when no rows qualify? - Not answered. What does
COUNT(amount)return when no rows qualify? - Not answered. What is
AVG(score)for scores10,20, andNULL? - Not answered. What is
COUNT(DISTINCT category)forA,A,B, andNULL? - Not answered. How many groups does
GROUP BY regionform? - Not answered. Which customers does this query find?
- Not answered. Why does this query omit departments with no sales since 2026 began?
- Not answered. Which clause should filter groups whose total sales exceed 1,000?
- Not answered. What defect causes the duplicated matches?
- Not answered. Which predicate produces each unordered employee pair exactly once?
- Not answered. How many rows result from joining students through enrollments?
- Not answered. What should you check when a many-to-one join doubles some sales?
- Not answered. Why is
SELECT DISTINCTa risky repair for an unexpectedly duplicating join? - Not answered. Which rows can match because of missing parentheses?
- Not answered. How many rows does the full outer join return?
- Not answered. How many rows do
UNION ALLandUNIONreturn? - Not answered. How many rows does a cross join produce?
- Not answered. Why do authors without books disappear from this join chain?
- Not answered. Does a NULL join value match another NULL join value?
- Not answered. Why does a window total repeat an inflated value after a join?
- Not answered. What is guaranteed by
SELECT id FROM tasks LIMIT 1withoutORDER BY? - Not answered. Which 2026 rows can an inclusive
BETWEENfilter accidentally omit? - Not answered. Why does this expression count every row?
- Not answered. What does
SUM(CASE WHEN paid THEN amount END)return when no row is paid? - Not answered. When is
LEFT JOIN ... WHERE right.key IS NULLa reliable anti-join? - Not answered. What happens when a left-table filter is placed inside the
ONclause? - Not answered. What is wrong with grouping by both customer and order when one row per customer is required?
- Not answered. Does a group containing only NULL scores pass
HAVING AVG(score) >= 0? - Not answered. Which checks help find where unexpected fan-out begins?
- Not answered. Which rewrite preserves all accounts while counting only successful logins?