QUERY expression (named query expression) 

QUERY expressions ( named query expressions ) are required to generate an unordered result table in a SELECT statement (named select statement).

Syntax

<named query expression> ::= <named query   term> | <named query expression> UNION [ALL] <query term> | <named query   expression> EXCEPT [ALL] <query term>

named query term, query term

Explanation

If the QUERY expressions consists of more than one QUERY specification (query spec) (specified in named query term or in query term ), the only the first QUERY specification in the QUERY expression may be a QUERY specification ( named query spec ).

If the QUERY expressions consists of only one QUERY specification (named query spec) (specified in named query term ), the result of the expression is the unchanged result of the QUERY specification.

If a QUERY expression consists of more than one QUERY specification, the number of selected columns in all QUERY specifications of the QUERY expression must be the same. The respective ith selected columns of the QUERY specifications must be comparable.

Column type (select column)

 

Numeric columns

Are comparable. If all ith selected columns are numeric columns, the i th column of the result table is a numeric column.

Alphanumeric columns, code attribute BYTE

Are comparable.

Alphanumeric columns, code attribute ASCII, EBCDIC

Are comparable. Are also comparable with date, time, and timestamp values.

All ith columns are date v values

The ith column of the result table is a date value.

All ith columns are time values

The ith column of the result table is a time value.

All ith columns are timestamp values

The ith column of the result table is a timestamp value.

Columns of the type BOOLEAN

Are comparable.

All ith columns are of the type BOOLEAN

The ith column of the result table is of the type BOOLEAN.

Columns of any other data type (not mentioned above)

The ith column of the result table is an alphanumeric column. Comparable columns with differing code attributes are converted.

 

If columns are comparable but have different lengths, the corresponding column of the result table has the maximum length of the underlying columns.

Column names in the result table

The names of the result table columns are formed from the names of the selected columns of the first QUERY specification.

Let T1 be the left operand of UNION, EXCEPT, or INTERSECT (defined in named query term ). Let T2 be the right operand. Let R be the result of the operation on T1 and T2.

If parentheses are missing, then INTERSECT will be evaluated before UNION and EXCEPT. UNION and EXCEPT have the same precedence and will be evaluated from left to right in the case that parentheses are missing.