DB2 Version 9.7 for Linux, UNIX, and Windows

PRIOR unary operator

The PRIOR unary operator is for use only in the CONNECT BY clause of hierarchical queries (SQLSTATE 428H4).

Read syntax diagramSkip visual syntax diagram
>>-PRIOR--expression-------------------------------------------><

The CONNECT BY clause performs an inner join between the intermediate result table Hn of the hierarchical query and the source result table specified in the FROM clause. All column references to tables that are referenced in the FROM clause, and which are arguments to the PRIOR operator, are considered to be ranging over Hn.

The primary key of the intermediate result table Hn is typically joined to the foreign keys of the source result table to recursively traverse the hierarchy.
   CONNECT BY PRIOR T.PK = T.FK
If the primary key is a composite key, care must be taken to prefix each column with PRIOR:
   CONNECT BY PRIOR T.PK1 = T.FK1 AND PRIOR T.PK2 = T.FK2
expression
Any expression that does not contain a NEXT VALUE expression, an hierarchical query construct (such as the LEVEL pseudocolumn), the SYS_CONNECT_BY_PATH function, or an OLAP function (SQLSTATE 428H4).

The result data type of the operator is the result data type of the expression.

Notes:

Example: