Bird
0
0

Why is the HAVING clause necessary in SQL when filtering grouped data?

hard📝 Conceptual Q10 of 15
SQL - GROUP BY and HAVING

Why is the HAVING clause necessary in SQL when filtering grouped data?

ABecause HAVING replaces GROUP BY
BBecause HAVING sorts the grouped data
CBecause WHERE filters groups after aggregation
DBecause WHERE cannot filter aggregated results
Step-by-Step Solution
Solution:
  1. Step 1: Understand WHERE limitations

    WHERE filters rows before aggregation and cannot use aggregate functions.
  2. Step 2: Role of HAVING

    HAVING filters groups after aggregation using aggregate functions like SUM, COUNT.
  3. Final Answer:

    Because WHERE cannot filter aggregated results -> Option D
  4. Quick Check:

    HAVING needed for aggregate filtering = C [OK]
Quick Trick: HAVING filters aggregated groups WHERE cannot [OK]
Common Mistakes:
MISTAKES
  • Thinking WHERE can filter aggregates
  • Confusing HAVING with sorting

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes