Union

UNION can be used to combine results from multiple SELECT statements.

See also

Union (SQL)

Table of contents

Union All

If duplicates are allowed, use UNION ALL.

cr> select name from photos
... union all
... select name from countries
... union all
... select name from photos
... order by name;
+--------------+
| name         |
+--------------+
| Austria      |
| Berlin Wall  |
| Berlin Wall  |
| Eiffel Tower |
| Eiffel Tower |
| France       |
| Germany      |
| South Africa |
| Turkey       |
+--------------+
SELECT 9 rows in set (... sec)

Union Distinct

To remove duplicates, use UNION DISTINCT or simply UNION.

cr> select name from photos
... union distinct
... select name from countries
... union
... select name from photos
... order by name;
+--------------+
| name         |
+--------------+
| Austria      |
| Berlin Wall  |
| Eiffel Tower |
| France       |
| Germany      |
| South Africa |
| Turkey       |
+--------------+
SELECT 7 rows in set (... sec)