As UNION ALL is faster than UNION, would you use UNION ALL to combine 2 tables which dont have any duplicates ? Why/Why not ?
Asked
Active
Viewed 66 times
1 Answers
1
You should always default to UNION ALL
when you want to combine tables. UNION
incurs overhead for removing duplicates -- and in almost every database, you get the overhead even when there are no duplicates.
You should only use UNION
when you specifically want to incur that overhead because you really do want to remove duplicates.

Gordon Linoff
- 1,242,037
- 58
- 646
- 786
-
Understood, thanks for the response. – ruko Sep 17 '21 at 23:14
-
I'd be recommending beginners to use `UNION` unless they really understand the schema and can be sure there will _never_ be duplicates. (And beginners are poor at understanding that.) Unexpected duplicates cause all sorts of subtle errors, especially in aggregates (`SUM, COUNT, etc`). – AntC Sep 18 '21 at 23:10