UNION
suggest changeSyntax
- 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
ORDER BY
- ( SELECT … ) UNION ( SELECT … ) ORDER BY … – resolves the ambiguity
Remarks
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).
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents