Skip to main contentSkip to solution

What is the use of "HAVING" clause in SELECT query?

Solution

✅ Correct Option: 1

HAVING filters the groups created by GROUP BY. It is applied after grouping, so it can test aggregate values such as COUNT(∗)\text{COUNT}(*), SUM()\text{SUM}() or AVG()\text{AVG}().

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.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question