Skip to main contentSkip to solution

In SQL, which clause is used to specify conditions on the rows with GROUP BY clause?

Solution

✅ Correct Option: 1

The HAVING clause filters groups created by GROUP BY. It is applied after grouping, so it can use aggregate functions 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: WHERE filters individual rows before grouping and cannot use aggregate functions.

Option 3: DISTINCT removes duplicate rows from the output; it does not set conditions.

Option 4: ORDER BY only sorts the result; it does not filter anything.

Keyboard Shortcuts

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