UNION is a set operator that concatenates rows from multiple SELECT statements and removes exact duplicates in the combined output. Each SELECT must return the same number of columns, and corresponding columns must be type-compatible. The operator applies DISTINCT semantics automatically, so any repeated rows are eliminated. Column names in the final result are taken from the first SELECT. Optional ORDER BY or LIMIT clauses apply to the entire unioned set when placed after the last SELECT. Because UNION performs duplicate elimination, it can be slower than UNION ALL, which skips that step.
SQL-92 standard
UNION removes duplicate rows after merging result sets, while UNION ALL keeps all rows and runs faster because it skips de-duplication.
Only the number and data types must align. The final column names come from the first SELECT; later names are ignored.
Put ORDER BY after the last SELECT so it sorts the entire combined output. Using ORDER BY inside individual SELECTs usually raises an error.
Yes. UNION performs duplicate elimination, which adds sorting or hashing overhead. Prefer UNION ALL when duplicates are acceptable.