skip to main content
SQL Statements for Flat-File Drivers : Select Statement : Union Operator
  
Union Operator
The Union operator combines the results of two Select statements into a single result. The single result is all the returned rows from both Select statements. By default, duplicate rows are not returned. To return duplicate rows, use the All keyword (UNION ALL). The form is:
SELECT statement
UNION ALL
SELECT statement
When using the Union operator, the Select lists for each Select statement must have the same number of column expressions with the same data types, and must be specified in the same order. For example:
SELECT last_name, salary, hire_date FROM emp
UNION
SELECT name, pay, birth_date FROM person
This example has the same number of column expressions, and each column expression, in order, has the same data type.
The following example is not valid because the data types of the column expressions are different (salary from emp has a different data type than last_name from raises). This example does have the same number of column expressions in each Select statement but the expressions are not in the same order by data type.
SELECT last_name, salary FROM emp
UNION
SELECT salary, last_name FROM raises