Evaluation Order of WHERE, GROUP BY, and HAVING Clauses - Teradata Database

SQL Data Manipulation Language

Product
Teradata Database
Release Number
15.10
Language
English (United States)
Last Update
2018-10-06
dita:id
B035-1146
lifecycle
previous
Product Category
Teradata® Database

Evaluation Order of WHERE, GROUP BY, and HAVING Clauses

When the WHERE, GROUP BY, and HAVING clauses are used together in a SELECT statement, the order of evaluation is as follows:

1 WHERE

2 GROUP BY

3 HAVING

Tables referenced in a HAVING clause must be specified in one of the following:

  • FROM clause
  • WHERE clause
  • SELECT expression list
  • Non-aggregate condition
  • You can use the HAVING clause when referencing columns from two or more tables.