SQL query detective
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
- Not answered. How many rows does this inner join return?
- Not answered. Which customer names does this query return?
- Not answered. What does the query return with the paid filter moved into
ON? - Not answered. What are the counts for a customer with no orders?
- Not answered. What
item_totaldoes this query report? - Not answered. Which approaches give correct item and payment totals per order?
- Not answered. What does
NULL = NULLevaluate to in a SQL predicate? - Not answered. Which standard SQL predicate treats two NULLs as equal?
- Not answered. Which values does this
NOT INquery return? - Not answered. Which values does this
NOT EXISTSquery 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 leave out departments with no sales since the start of 2026?
- Not answered. Which clause keeps only groups with total sales over 1,000?
- Not answered. What causes the duplicate matches?
- Not answered. Which predicate produces each unordered employee pair exactly once?
- Not answered. How many rows does joining students through enrollments return?
- Not answered. A many-to-one join doubles some sales. What should you check?
- Not answered. Why is
SELECT DISTINCTa risky fix for a join that duplicates rows? - 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 key match another NULL?
- Not answered. Why does this window total show an inflated value?
- Not answered. What does
SELECT id FROM tasks LIMIT 1guarantee withoutORDER BY? - Not answered. Which 2026 rows can this inclusive
BETWEENfilter miss? - 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 you put a left-table filter in
ON? - Not answered. What's wrong with this query if you need one row per customer?
- 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 query keeps every account but counts only successful logins?