Having (SQL)
A HAVING clause in SQL specifies that an SQL SELECT statement must only return rows where aggregate values meet the specified conditions.
A HAVING clause in SQL specifies that an SQL SELECT statement must only return rows where aggregate values meet the specified conditions. SELECT DeptID, SUM(SaleAmount) FROM Sales WHERE SaleDate = '2000-01-01' GROUP BY DeptID HAVING SUM(SaleAmount) > 1000 Referring to the sample tables in the Join example, the following query will return the list of departments which have more than 1 employee: SELECT DepartmentName, COUNT(*) FROM Employee JOIN Department ON Employee.DepartmentID = Department.DepartmentID GROUP BY DepartmentName HAVING COUNT(*) > 1; HAVING is convenient, but not necessary. Code equivalent to the example above, but without using HAVING , might look like: SELECT * FROM ( SELECT DepartmentName AS deptNam, COUNT(*) AS empCount FROM Employee AS emp JOIN Department AS dept ON emp.DepartmentID = dept.DepartmentID GROUP BY deptNam ) AS grp WHERE grp.empCount > 1; ==External links== The HAVING and GROUP BY SQL clauses SQL Aggregate Functions
References
No reference rows published for this article.
Cite this article
MLA
"Having (SQL)." encyclopegia.org, 2025, https://encyclopegia.org/wiki/having-sql. Accessed 24 November 2026.
Chicago
"Having (SQL)." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/having-sql.
APA
encyclopegia.org. (2025). Having (SQL). Retrieved November 24, 2026, from https://encyclopegia.org/wiki/having-sql
Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON