Having Clause
- Last Updated: May 15, 2020
- 1 minute read
- DataDirect Connectors
- JDBC
- IBM Db2 5.1
- MySQL 5.1
- Progress OpenEdge 5.1
- SAP Sybase 5.1
- Documentation
Purpose
Specifies conditions for groups of rows (for example, display only the departments that have salaries totaling more than $200,000). This clause is valid only if you have already defined a Group By clause.
Syntax
HAVING expr1rel_operatorexpr2
where:
- expr1
- is a column name, a constant value, or an expression. An expression does not have to match a column expression in the Select clause.
- expr2
- is a column name, a constant value, or an expression. An expression does not have to match a column expression in the Select clause.
- rel_operator
- is the relational operator that links the two expressions.
Example
This example returns only the departments that have salaries totaling more than $200,000:
SELECT dept_id, sum(salary) FROM emp
GROUP BY dept_id HAVING sum(salary) > 200000