What does UNION do? What is the difference between UNION and UNION ALL?

 Posted by Manicse on 11/2/2016 | Category: Sql Server Interview questions | Views: 159 | Points: 40
Answer:

UNION merges the contents of two structurally-compatible tables into a single combined table. The difference between UNION and UNION ALL is that UNION will omit duplicate records whereas UNION ALL will include duplicate records.

It is important to note that the performance of UNION ALL will typically be better than UNION, since UNION requires the server to do the additional work of removing any duplicates. So, in cases where is is certain that there will not be any duplicates, or where having duplicates is not a problem, use of UNION ALL would be recommended for performance reasons.


| Alert Moderator 

Comments or Responses

Login to post response