This topic describes the UNION clause.


The following statement provides the syntax of the UNION clause:

select_statement UNION [ ALL ] select_statement


select_statement is a SELECT statement that does not contain an ORDER BY or FOR UPDATE clause. You can enclose the ORDER BY clause in parentheses to attach the clause to a sub-expression. If parentheses are not used, these clauses are applied to the result of the UNION clause instead of the expression on the right side.

The UNION operator computes the set union of the rows that are returned by the involved SELECT statements. If a row is included in at least one of two result sets, the row is in the set union of the two result sets. The two SELECT statements that represent the direct operands of the UNION clause must generate the same number of columns. The corresponding columns must be of compatible data types.

The result of the UNION clause contains duplicate rows only if the ALL option is specified. The ALL option prevents duplicate rows from being eliminated.

Unless otherwise specified in parentheses, multiple UNION operators in the same SELECT statement are evaluated from left to right.

The FORUPDATE clause may not be specified for a UNION result or for an input of a UNION.