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…..

Comments

Popular posts from this blog

Best Laptop under 30000 in India

Today Deals: 40% Off on Fab phones fest and get more offer on Fashion, Laptop and much more product [06-Feb]

How to reduce upload speed in utorrent