Previous Topic: GROUP BY ClauseNext Topic: SELECT Clause


HAVING Clause

HAVING search-condition

Produces an intermediate result table by applying the search-condition to each group of R, where R is the result of the previous clause. If that clause is not GROUP BY, all rows of R are considered as one group. The result table contains those groups of R for which the search condition is true.

The search-condition describes a search condition that conforms to the following rules:

  1. The condition is formed (see Search Conditions).
  2. Each column-name in the search-condition must:
    1. Unambiguously identify a grouping column of R, or
    2. Be a correlated reference, or
    3. Be specified within a function.

A group of R to which the search condition is applied supplies the argument for each function in the search condition, except for any function whose argument is a correlated reference.

If the search condition contains a subquery, the subquery can be thought of as being executed each time the search condition is applied to a group of R, and the results used in applying the search condition. In actuality, the subquery is executed for each group only if it contains a correlated reference.

A correlated reference to a group of R must either identify a grouping column or be contained within a function.

The HAVING clause must not be used in: