The Oracle PL/SQL HAVING clause is used to filter or restrict the groups formed by the GROUP_BY clause. It follows the GROUP_BY clause in the SELECT statement. The HAVING clause can also precede the GROUP_BY clause, but this isn't logical and is not recommended. All grouping is performed (and group functions executed) prior to evaluating the HAVING clause.
Difference between WHERE and HAVING
The WHERE clause will filter or limit rows as they are selected from the table, but before grouping is done. The HAVING clause will filter rows after the grouping.
SELECT <column list>, <group by function>
FROM <table name>
GROUP_BY <column list>
HAVING <group by function condition>
SELECT JOB_ID, SUM(SALARY)
HAVING SUM(SALARY) > 10000
Related Code Snippets:
- Having Clause - Some example of using the 'HAVING' clause with 'GROUP BY'.