Skip to content
UoL CS Notes

UNION

COMP207 Lectures

This is basically the same as in mathematical sets. Consider the following table:

birtday first_name family_name e_id
1990-11-10 Anne Smith 1
2000-02-05 David Jones 2
2995-05-09 William Taylor 3

Executing the following query would give the following table:

SELECT first_name AS name
FROM Employees
UNION
SELECT family_name
FROM Employees;
name
Anne
David
William
Smith
Jones
Taylor

The name of the column comes from the first SELECT statement.

The things in the UNION must have similar data-types and also the same number of columns.

Similar Data-Types

Different implementations have different definitions of what classes as a “similar data-type”. Generally you can mix most things but you should check the docs for your specific implementation.