Difference Between Union and Union all

     Union and Union all both the command is used concatenate the two different SQL result. Then what will be the difference let see…

Union

The union is the command used to link the two SQL Result. But it removes all the Duplicate data. For example, Here I am taking two tables from AdventureWorks2008 Database and one is currency Table and another one is Currency rate table. In that table, I Taking Currency code and ToCurrencyCode Data.

Example For Union:-

You can see it will all the duplicate in the table. In Below picture only 105 rows are affected.

Union_Query_Result
Example For Union

Union All

  Union All doing the same job, But unlike Union it shows all the rows of the Data’s in two tables. It will not remove any duplicate rows in the table.

Example for Union all:
 

Union_All_Query_Result
Example For Union All

With this example, I think you get clear about union and union all command’s. If you have any suggestion please let me know. See next time with another post…..

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Comodo SSL