WITH statements in the SQL builder

A WITH statement is composed of one or more common table expressions and a SELECT statement. A common table expression defines a named results table that can be specified as a table in the FROM clause of a subsequent SELECT statement. You can create WITH statements only if you are using IBM® DB2® database.

Common table expressions

You can use a common table expression in the following ways:

When you are building a WITH statement, you use the nodes in the Outline view to select the components of the WITH statement to define in the SQL builder. The SELECT statement at the root node represents the WITH statement. You use the WITH WithTable node to define the common table expressions. The SELECT clause that is a sibling of the WITH WithTable node is referred to as the WITH statement SELECT. You must first define common table expressions, and then build the WITH statement SELECT by using the tables that are defined in the common table expressions. To complete the common table expression, you define a temporary table and its columns that is based on a SELECT statement's result set. After you define the temporary table in the common table expression, you can add it to the WITH statement SELECT.


Feedback