What is the use of "HAVING" clause in SELECT query?
What is the use of "HAVING" clause in SELECT query?
Solution
HAVING filters the groups created by GROUP BY. It is applied after grouping, so it can test aggregate values such as , or .
Example: SELECT dept, COUNT(*) FROM emp GROUP BY dept HAVING COUNT(*) > 5;
Option 2: ORDER BY only sorts the result. Being usable alongside it is not the purpose of HAVING.
Option 3: WHERE filters individual rows before grouping, while HAVING filters groups after grouping. The two can appear in one query, but that is not what HAVING is for.
Option 4: this names the statement HAVING appears in, not what it does.
WHERE cannot use aggregate functions, but HAVING can.
Related questions:
2026: 19 May Shift 1
2025: 13 May Shift 2
2025: 13 May Shift 2