SQL UNION vs UNION ALL Operator Usage
UNION:
UNION combines the result set of two or more queries into a single result set. UNION removes duplicate records (where all columns in the results are the same).
UNION ALL:
UNION combines the result set of two or more queries into a single result set. UNION ALL does not remove duplicate records.
Important points:
The following points need to be considered when using the UNION or UNION ALL operator:
- The number of columns and sequence of columns must be the same in all queries
- The data types must be compatible.