Thursday, October 16, 2008

Difference between UNION and UNION ALL

The UNION command is used to select related information from two or more tables, like the JOIN statement. Union combines the result sets of two or more queries into a single result set, which includes all rows that belong to all queries in the union. To use Union, the number and the order of the columns and data type of the columns selected must be the same in all queries.

 

Difference
The UNION command only selects distinct values.
The UNION ALL command is equal to the UNION command, but UNION ALL selects all alues.

No comments: