Bird
0
0

When should you use HAVING instead of WHERE in a SQL query?

easy📝 Conceptual Q2 of 15
SQL - GROUP BY and HAVING
When should you use HAVING instead of WHERE in a SQL query?
ATo filter groups after aggregation
BTo filter individual rows before grouping
CTo sort the result set
DTo rename columns in the output
Step-by-Step Solution
Solution:
  1. Step 1: Identify purpose of HAVING

    HAVING filters groups after aggregation functions like SUM or COUNT are applied.
  2. Step 2: Differentiate from WHERE

    WHERE filters rows before grouping, so it cannot filter aggregated groups.
  3. Final Answer:

    HAVING filters groups after aggregation -> Option A
  4. Quick Check:

    Filter groups after aggregation = HAVING [OK]
Quick Trick: HAVING filters groups after aggregation, WHERE filters rows before [OK]
Common Mistakes:
MISTAKES
  • Using HAVING to filter rows
  • Using WHERE to filter aggregated groups
  • Confusing sorting with filtering

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes