Challenge - 5 Problems
WHERE vs HAVING Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Understanding WHERE clause filtering
Which statement best describes when the WHERE clause is applied in an SQL query?
Attempts:
2 left
💡 Hint
Think about when rows are removed in the process: before or after grouping?
✗ Incorrect
The WHERE clause filters individual rows before any grouping or aggregation occurs. It decides which rows enter the grouping stage.
🧠 Conceptual
intermediate2:00remaining
Understanding HAVING clause filtering
Which statement best describes when the HAVING clause is applied in an SQL query?
Attempts:
2 left
💡 Hint
Think about filtering groups, not rows.
✗ Incorrect
The HAVING clause filters groups after aggregation. It decides which groups appear in the final result.
❓ query_result
advanced3:00remaining
Output of WHERE vs HAVING filtering
Given the table
sales with columns region and amount, what is the output of this query?SELECT region, SUM(amount) AS total FROM sales WHERE amount > 100 GROUP BY region;SQL
Table sales: region | amount -------|------- East | 150 East | 90 West | 200 West | 50 South | 120 South | 80
Attempts:
2 left
💡 Hint
Remember WHERE filters rows before grouping.
✗ Incorrect
The WHERE clause removes rows where amount ≤ 100 before grouping. So only amounts 150, 200, and 120 remain. The SUM is over these filtered rows.
❓ query_result
advanced3:00remaining
Output of HAVING filtering after aggregation
Given the same
sales table, what is the output of this query?SELECT region, SUM(amount) AS total FROM sales GROUP BY region HAVING SUM(amount) > 200;SQL
Table sales: region | amount -------|------- East | 150 East | 90 West | 200 West | 50 South | 120 South | 80
Attempts:
2 left
💡 Hint
HAVING filters groups after SUM is calculated.
✗ Incorrect
The SUM per region is East=240, West=250, South=200. HAVING keeps groups with total > 200, so South is excluded.
📝 Syntax
expert2:00remaining
Identify the syntax error in combined WHERE and HAVING query
Which option contains a syntax error in this query?
SELECT region, COUNT(*) FROM sales WHERE region = 'East' HAVING COUNT(*) > 1 GROUP BY region;Attempts:
2 left
💡 Hint
Check the order of clauses in SQL syntax.
✗ Incorrect
In SQL, the GROUP BY clause must come before HAVING. Placing HAVING before GROUP BY causes a syntax error.