Reference Guide > TDV SQL Keywords and Syntax > UNION
 
UNION
UNION works like UNION ALL, except that it does not produce duplicate rows.
Syntax
<query_expression>
UNION
<query_expression>
Remarks
The SELECT clause lists in the two queries must have the same number of projections.
Corresponding columns in the two queries must be listed in the same order.
Corresponding columns must have the same data type or must be implicitly convertible to the same data type.
An ORDER BY clause can appear in only the final query of the UNION statement. The sort is applied to the final combined result.
GROUP BY and HAVING can be specified in the individual queries only. They cannot be used to affect the final result.
For the purposes of a SET operation, two NULLs are duplicates of each other.
Example
The following sample query lists the states where authors and publishers are located in the authors table and publishers table, respectively.
SELECT state FROM authors
UNION
SELECT state FROM publishers