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 ALLdoes not remove duplicate rows from the result set.- The first and all subsequent
SELECTstatements must select the same number of columns. - MemSQL does not support
ORDER BYorGROUP BYon the result of aUNION. For example, the query(SELECT * FROM table_a UNION ALL SELECT * FROM table_b) GROUP BY xis not supported.
Example
memsql> SELECT * FROM table_a UNION ALL SELECT * FROM table_b;
memsql> SELECT * FROM table_a UNION SELECT * FROM table_b;