Back to Course
SQL for Testers

HAVING

Definition

HAVING filters groups after aggregation, similar to how WHERE filters individual rows before aggregation. It is used specifically to filter on the result of an aggregate function.

Example

SELECT department, COUNT(*) AS emp_count
FROM employees
GROUP BY department
HAVING COUNT(*) > 10;

WHERE vs HAVING

WHERE cannot reference aggregate functions because it runs before grouping happens; HAVING runs after grouping, so it can filter on aggregated values like counts or sums.

Ready to master real-world software testing?

Learn manual and automation testing hands-on with mentor-led sessions.

Explore Course