Outdated Version
You are viewing an older version of this section. View current production version.
UNION
Combines results from multiple SELECT statements. UNION DISTINCT
removes duplicate rows, while UNION ALL
does not remove them. UNION
is equivalent to UNION DISTINCT
.
Syntax
SELECT ...
UNION [ALL | DISTINCT] SELECT ...
[UNION [ALL | DISTINCT] SELECT ...]
Remarks
- The first and all subsequent
SELECT
statements must select the same number of columns.
Examples
memsql> SELECT * FROM table_a UNION ALL SELECT * FROM table_b;
memsql> SELECT * FROM table_a UNION SELECT * FROM table_b;