Common table expressions

The WITH prefix to the SELECT statement affords you the opportunity to define common table expressions. Common table expressions are temporary views that are known only within the scope of a single SELECT statement. They permit you to write queries more easily, and to write queries that could not otherwise be expressed.

Common table expressions are useful or may be necessary if a query involves multiple aggregate functions or defines a view within a stored procedure that references program variables. Common table expressions also provide a convenient means to temporarily store sets of values.


Using common table expressions
Specifying multiple correlation names
Using multiple table expressions
Where common table expressions are permitted
Typical applications of common table expressions
Recursive common table expressions
Parts explosion problems
Data type declarations in recursive common table expressions
Least distance problem
Using multiple recursive common table expressions