Both UNION and UNION ALL operators are used to combine the results of two or more SELECT statements. However the two differ as below:
1) UNION performs a DISTINCT on the result set, removing any duplicate rows.There is a performance hit when using UNION since there is an additional effort of removing duplicates.
Below is the syntax for using UNION.
SELECT * FROM Table1
UNION
SELECT * FROM Table2
2) UNION ALL does not remove duplicates hence it faster than UNION.
Below is the syntax for using UNION ALL.
SELECT * FROM Table1
UNION All
SELECT * FROM Table2
0 Comment(s)