Thursday, October 18, 2007

SQL : Difference Between Union and Union All (Set Operators)

 
 
Union:
 
The Set operator Union, will combine the results of first query and second query, but it doesnt displays the
 
records common to both the queries..
 
 
 Union :  ( Records of Query 1 + Records Of Query 2) - (Records common to both the queries)
 
Usage : (Query 1 ) Union (Query 2)
 
Union All :
 
The Set operator Union, will combine the results of first query and second query, and records common to both the queries..
 
 Union All :  ( Records of Query 1 + Records Of Query 2) + (Records common to both the queries)
 
 Usage : (Query 1 ) Union all (Query 2)
 
Note : The rules of Set operators are..
 
   The number of colums and datatypes of coloums (not colum names ) returned by the query 1 should be same with the number of coloums retrived by the query two.

No comments: