MySQL union and union all
About 273 wordsLess than 1 minuteDecember 4, 2024
UNION
The UNION operator is used to combine the result sets of two or more SELECT statements and removes duplicate rows from the result set. By default, UNION performs deduplication.
UNION ALL
The UNION ALL operator also combines the result sets of two or more SELECT statements but does not remove duplicate rows, retaining all results.
Differences
Deduplication
UNIONperforms deduplication, keeping only unique rows.UNION ALLdoes not deduplicate, retaining all rows, including duplicates.
Performance
UNIONincurs higher overhead due to deduplication, resulting in slightly lower performance.UNION ALLhas higher performance as it does not perform deduplication.
