Skip to main contentSkip to solution

The HAVING clause is used to ________.

Solution

✅ Correct Option: 2

HAVING sets a condition on the groups formed by the GROUP BY clause, so it is used together with GROUP BY. It is applied after grouping, which is why it can use aggregate functions such as COUNT()\text{COUNT()}, SUM()\text{SUM()} and AVG()\text{AVG()}.

Example: SELECT dept, COUNT(*) FROM emp GROUP BY dept HAVING COUNT(*) > 5;


Option 1: this describes WHERE, which filters individual rows before grouping. HAVING works after grouping.

Options 3 and 4: sorting is done by ORDER BY and joining tables by JOIN.

WHERE cannot use aggregate functions, while HAVING can.

Keyboard Shortcuts

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