Syntax

The syntax of the UNION clause is as follows:

select_statement UNION [ ALL ] select_statement

Description

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 it to a sub-expression. Without parentheses, these clauses are applied to the result of the UNION clause, not to the expression on the right side.

The UNION operator computes the set union of the rows 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 produce 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 elimination of duplicate rows.

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

The FOR UPDATE clause may not be specified either for a UNION result or for an input of a UNION clause.