Aggregation & GROUP BY · SQL SQL

What is the primary purpose of the SQL HAVING clause in an aggregation query?

Practice question from Aggregation & GROUP BY (SQL SQL), with the correct answer and a step-by-step solution.

easy · MCQ · Q-C37B6C

What is the primary purpose of the SQL HAVING clause in an aggregation query?

  1. A.To filter individual rows before any grouping or aggregation takes place.
  2. B.To filter groups based on aggregate function results after the GROUP BY phase.Correct answer
  3. C.To sort the final result set in ascending or descending order.
  4. D.To join two or more tables based on a common column.

Solution

The HAVING clause is evaluated after the GROUP BY phase, allowing you to filter groups based on the results of aggregate functions (like SUM, COUNT, AVG). In contrast, the WHERE clause filters individual rows before grouping occurs.

More from Aggregation & GROUP BY

All of Aggregation & GROUP BY

Practise more SQL

Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.

Start practising free

Free to start · No credit card needed