If we want to combine two or more result sets into one result set, we use Union and unite all commands.
There are some differences between Union and Union all.
- Union All will not eliminate the duplicate records.
Union removes the duplicate records. - Union All does not use distinct sort, i.e. it is faster than union.
Union uses a distinct sort. This is the reason it is slower than union all.
Let’s do an example,
We have table: tblEmployeeA

Other table is tblEmployeeB

Apply union and union all commands on the tables, given above.
- SELECT Name,Address,salary FROM tblEmployeeA
- UNION
- SELECT Name,Address,salary FROM tblEmployeeB

- SELECT Name,Address,salary FROM tblEmployeeA
- UNION ALL
- SELECT Name,Address,salary FROM tblEmployeeB



Paramjit SinghPosted Jul 18, 2016, 9:53 AM
Thanks
kalu singh raoPosted Jul 18, 2016, 9:00 AM
Nice...