Difference between UNION and UNION ALL

Unions are used to join tables on column level, usually when we need to join two sets from the same table into one result. But what is difference in UNION and UNION ALL?


  • simply joins two results and does not do anything else with result set.


  • also joins results but selects only distinct rows from each select statement. It means, that UNION in addition excludes duplicate rows. Therefore UNION can be slower than UNION ALL, because has to order data to find duplicates.
programming/mssql/miscellaneous.txt · Last modified: 2018-06-21 19:48 (external edit)
CC Attribution-Noncommercial-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0