- UNION DISTINCT -- dedups after combining the SELECTs
- UNION ALL -- non dedup (faster)
- UNION -- the default is DISTINCT
- SELECT ... UNION SELECT ... -- is OK, but ambiguous on
- ( SELECT ... ) UNION ( SELECT ... ) ORDER BY ... -- resolves the ambiguity
UNION does not use multiple CPUs.
UNION always* involves a temp table to collect the results. *As of 5.7.3 / MariaDB 10.1, some forms of UNION deliver the results without using a tmp table (hence, faster).
Combining and merging data on different MySQL tables with the same columns into unique rows and running query
This modified text is an extract of the original Stack Overflow Documentation created by following contributors
and released under CC BY-SA 3.0