Previous Topic: WHERE ClauseNext Topic: HAVING Clause


GROUP BY Clause

GROUP BY

Produces an intermediate result table by grouping the rows of R, where R is the result of the previous clause.

column-name

The column-name must unambiguously name a column of R. Each column named is called a group column. The names must be separated by commas.

The result of GROUP BY is a set of groups of rows. In each group of more than one row:

  1. All values of each grouping column are equal.
  2. All rows with the same set of values of the grouping columns are in the same group.

For the purpose of grouping, all null values within a grouping column are considered equal.

Because every row of a group contains the same value of any grouping column, the name of a grouping column can be used in a search condition in a HAVING clause or an expression in a SELECT clause. In each case, the reference specifies only one value for each group.

GROUP BY must not be used in: