Typical applications of common table expressions

In general, common table expressions are useful whenever a table expression must appear multiple times within a single query. The following typical situations are suited to common table expressions.

  • Queries that involve multiple aggregate functions.

  • Views within a procedure that must contain a reference to a program variable.

  • Queries that use temporary views to store a set of values.

This list is not exhaustive; you may encounter many other situations in which common table expressions are useful.


Multiple aggregate functions
Views that reference program variables
Views that store values