Outdated Version
You are viewing an older version of this section. View current production version.
UNION
Combines results from multiple SELECT statements. UNION
removes duplicate rows, while UNION ALL
leaves them. UNION DISTINCT
has the same semantics as the default UNION
.
SELECT ...
UNION [ALL | DISTINCT] SELECT ...
[UNION [ALL | DISTINCT] SELECT ...]
Notes
UNION ALL
does not remove duplicate rows from the result set.- The first and all subsequent
SELECT
statements must select the same number of columns. - MemSQL does not support
ORDER BY
orGROUP BY
on the result of aUNION
. For example, the query(SELECT * FROM table_a UNION ALL SELECT * FROM table_b) GROUP BY x
is not supported.
Example
memsql> SELECT * FROM table_a UNION ALL SELECT * FROM table_b;
memsql> SELECT * FROM table_a UNION SELECT * FROM table_b;