UNION


The UNION operator merges two tables with identical structure to produce a single table. Its syntax is:
 table1 UNION table2

The tables on either side of the UNION operator may be base tables, views, or SELECT statements. Although not strictly necessary, it is hepful if both the fields in both tables are aliased so that the corresponding fields share the same column heading.

Example usage:

 (SELECT DISTINCT
    WorksNo AS EmployeeNo,
    "Personnel" AS Department,
    FirstName,
    LastName
  FROM PersonnelDept)
 UNION
 (SELECT DISTINCT
    OperatorNo AS EmployeeNo,
    "Technical Support" AS Department,
    FirstName,
    LastName
  FROM TechnicalSupport)

The above example returns all employees who work in either Personnel or Technical Support. Note the use of text literals to insert the department name in the results table.

[Return to SQL Syntax]