Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
What is the difference between union and unionall?

Thank You.
Posted
Comments
Sergey Alexandrovich Kryukov 1-Mar-13 10:52am    
Spam and incorrect type of question.
—SA

 
Share this answer
 
Comments
NeenaM 28-Feb-13 12:28pm    
Thanks for solution 2 it was really easy to understand
 
Share this answer
 
Comments
bbirajdar 27-Feb-13 12:21pm    
Best answer +5
UNION
The UNION command is used to select related information from two tables, much like the JOIN command. However, when using the UNION command all selected columns need to be of the same data type. With UNION, only distinct values are selected.

UNION ALL
The UNION ALL command is equal to the UNION command, except that UNION ALL selects all values.

The difference between Union and Union all is that Union all will not eliminate duplicate rows, instead it just pulls all rows from all tables fitting your query specifics and combines them into a table.

A UNION statement effectively does a SELECT DISTINCT on the results set. If you know that all the records returned are unique from your union, use UNION ALL instead, it gives faster results.

Example:
Table 1 : First,Second,Third,Fourth,Fifth
Table 2 : First,Second,Fifth,Sixth

Result Set:
UNION: First,Second,Third,Fourth,Fifth,Sixth (This will remove duplicate values)
UNION ALL: First,First,Second,Second,Third,Fourth,Fifth,Fifth,Sixth,Sixth (This will repeat values)

Good luck,
OI
 
Share this answer
 
Comments
fjdiewornncalwe 1-Mar-13 9:47am    
Plagiarized: Source

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900