Question:

What is the purpose of the HAVING clause in SQL?

Show Hint

A simple rule:WHERE` filters rows,HAVING` filters groups. You cannot use an aggregate function (likeCOUNT() > 5`) in aWHERE` clause, but you can in aHAVING` clause.
Updated On: Jul 2, 2026
  • To filter groups based on a condition
  • To filter rows based on a condition
  • To sort the result set
  • To join tables
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation

In SQL, theWHERE` clause and theHAVING` clause are both used for filtering, but they operate at different stages.
(B) TheWHERE` clause is used to filter individual rows from the tables before any grouping is done.
TheGROUP BY` clause is used to aggregate rows into groups based on some criteria, and aggregate functions (likeCOUNT()`,SUM()`,AVG()`) are calculated for each group.
(A) TheHAVING` clause is then used to filter these groups based on a condition involving the aggregate functions.
(C) TheORDER BY` clause is used to sort the final result set.
(D) TheJOIN` clause is used to combine rows from two or more tables.
Therefore, the purpose of theHAVING` clause is to filter groups based on a condition.
Was this answer helpful?
0
0