Saturday, June 9, 2007

SQL UNION ALL

SQL UNION ALL is combine the results of two queries together without filter out the same value(no distinct behavior).
The difference between UNION ALL and UNION is UNION only selects distinct values and UNION ALL selects all values.

Syntax - UNION ALL
(SQL Statement 1)
UNION ALL
(SQL Statement 2)

Below is example for SQL UNION

Company

Sales($)

Website

Sql Traniner2500http://www.sqltutorials.blogspot.com
BeautyCentury3000http://beautycentury.blogspot.com
TravelYourself2800http://travelyourself.blogspot.com
Table1

Sales

Website

2900http://www.sqltutorials.blogspot.com
3000http://beautycentury.blogspot.com
2800http://travelyourself.blogspot.com
Table2

SQL UNION ALL Statement
SELECT Sales FROM TABLE1
UNION ALL
SELECT Sales FROM TABLE2

Result
Sales
2500
3000
2800
2900
3000
2800

5 comments:

Pinal Dave said...

Good Article.
I have similar article written SQL SERVER - Union vs. Union All - Which is better for performance?

Regards,

Ashley said...

WoW nice blog buddy!Actually WoW is my favorite appreciation keyword. I also like to play. Wow Gold. I was looking for info regarding that and saw your website. Its nice and very interesting.

microtopic said...

hi good blog dear have one site relates to SQL and some good interview question SQL Questions

Mind said...

Great post

Mind said...

wow gold kaufen


Nice post