Quick Search:
 
 The Oracle PL/SQL HAVING Clause      [Return To Index] Jump to:  

Term: HAVING

Definition:
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.

Example Syntax:

SELECT <column list>, <group by function>
FROM <table name>
WHERE <conditions>
GROUP_BY <column list>
HAVING <group by function condition>


Example Usage:

SELECT JOB_ID, SUM(SALARY)
FROM EMPLOYEES
GROUP_BY JOB_ID
HAVING SUM(SALARY) > 10000


Related Links:

Related Code Snippets:
 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org