4.6. SET OPERATIONS

4.6.1. SET Operations — UNION , UNION ALL

4.6.1.1. UNION Operator

UNION Operator combines the results of two or more queries into a single result set consisting of all the rows belonging to all queries in the union. This is different from using joins that combine columns from two tables.

Two basic rules for combining the result sets of two queries with UNION are as follows.

The number and the order of the columns must be identical in all queries.

The data types must be compatible. See Table 4-8.

Syntax
{< query specification > | ( < query expression > ) }
UNION [ ALL ]
< query specification | ( < query expression > )
[ UNION [ ALL ] < query specification | ( < query expression > )
[ ...n ] ]
Arguments
< query_specification ...

Get Transact-SQL Desk Reference now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.