Sobes.tech
Middle

How is HAVING used in SQL?

sobes.tech AI

Answer from AI

The SQL HAVING operator is used to filter groups of records formed with GROUP BY. Unlike WHERE, which filters individual rows before grouping, HAVING filters already aggregated groups based on a specified condition.

Example:

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

This query will select only those departments that have more than 10 employees.