Show TOC Start of Content Area

Syntax documentationUNION  Locate the document in its SAP Library structure

The keyword UNION allows constructing the union of multiple query specifications. Duplicate rows are implicitly eliminated from the result set unless UNION ALL is specified. In addition, you can order the result of a union using the ORDER BY clause.

Syntax

Syntax

<query expression> ::= <query term>
                                  | <query expression> UNION ( ALL )? <query term>.

<query term>::= <query specification>
                       | '(' <query expression> ')'.

 

Examples

Example

SELECT employee_name FROM employees
UNION

SELECT name FROM more_employees

UNION. This SELECT statement determines the union of all the names of all employees from the tables employees and more_employees. The result set will not contain duplicate names.

Example

SELECT empid AS employee_id, sal AS salary FROM employees

UNION

SELECT empid AS employee_id, sal AS salary FROM more_employees

ORDER BY employee_id

UNION with an ORDER BY Clause. The result of the query is ordered by employee ID in ascending order. Note that the column name from the result table (employee_id) is used in the ORDER BY clause.

More Information

Query Specification

End of Content Area