Multiple choice technology databases

When do we use a HAVING clause?

  1. To limit the output of a query

  2. To limit the output of a query using an aggregate function only

  3. When GROUP by is used

  4. both b and c above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

HAVING filters aggregated results after GROUP BY, while WHERE filters rows before aggregation. The key distinction is that HAVING can use aggregate functions (COUNT, SUM, AVG, etc.) but WHERE cannot. Option C is incomplete because simply 'using GROUP BY' doesn't guarantee HAVING is needed; HAVING is specifically for filtering the grouped aggregates.