Difference between UNION and UNION ALL
A UNION statement goes with a SELECT DISTINCT on the results set we receive after UNION.
If you know that all the records you are getting are unique from your union the you should use UNION ALL instead. It will give you better performance as it doesn’t go for SELECT DISTINCT.IF you dont then you have to go with UNION.
Example is given below for both
First Table: 1,1,2,2,2,2,3
Second Table: 2,3,4,5
Union All:
1,1,2,2,2,2,3,2,3,4,5
Union:
1,2,3,4,5
I will explain both the above UNION , UNION ALL in detail with examples
Pawan Kumar
Pawankkmr@hotmail.com