Oracle 19c SQL

  1. Home
  2. Docs
  3. Oracle 19c SQL
  4. 2 Parts of Oracle SQL Query
  5. 2.7 HAVING Clause

2.7 HAVING Clause

A HAVING clause restricts the results of a GROUP BY in a Select Expression. The HAVING clause is applied to each group of the grouped data, similar to a WHERE clause. WHERE clause filters individual rows while HAVING clause filters grouped data.

SELECT Comm FROM Emp GROUP BY Comm;

      COMM
----------

      1400
       500
       300
         0

Filtering rows through WHERE clause.

SELECT Comm FROM Emp 
 WHERE Comm IS NOT NULL
 GROUP BY Comm;

      COMM
----------
      1400
       500
       300
         0

Filtering grouped rows through HAVING clause.

SELECT Comm FROM Emp 
 GROUP BY Comm
HAVING Comm IS NOT NULL;

      COMM
----------
      1400
       500
       300
         0

The difference between WHERE clause and HAVING clause is, WHERE is executed before GROUP BY. But having is performed after GROUP BY.

Check our next articles to understand execution order of different clauses in a statement.

Was this article helpful to you? Yes No

How can we help?