Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««12345

Combining union and union all Expand / Collapse
Author
Message
Posted Friday, March 16, 2012 8:08 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, April 7, 2014 4:29 AM
Points: 103, Visits: 30
got it right and learn a behaviour great love it
Post #1268257
Posted Friday, July 20, 2012 3:26 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, June 19, 2014 6:03 AM
Points: 287, Visits: 130
Answer of the question is wrong !!

select @@VERSION
create table #t1 (col int not null)
create table #t2 (col int not null)
create table #t3 (col int not null)

insert #t1 values (1), (1)
insert #t2 values (2)
insert #t3 values (3)

select COL from #t1
UNION
select COL from #t2
union all
select COL from #t3

select COL from #t1
UNION ALL
select COL from #t2
union all
select COL from #t3


Result:

Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (X64) Apr 22 2011 19:23:43 Copyright (c) Microsoft Corporation Data Center Edition (64-bit) on Windows NT 6.1 <X64> (Build 7600: )

COL
1
2
3

COL
1
1
2
3
Post #1332797
Posted Friday, July 20, 2012 7:28 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 3:36 PM
Points: 13,111, Visits: 11,946
tibrize (7/20/2012)
Answer of the question is wrong !!


Nope, you typed it wrong. The very last query is a UNION and you have UNION ALL

select @@VERSION
create table #t1 (col int not null)
create table #t2 (col int not null)
create table #t3 (col int not null)

insert #t1 values (1), (1)
insert #t2 values (2)
insert #t3 values (3)

select COL from #t1
UNION
select COL from #t2
union all
select COL from #t3

select COL from #t1
UNION ALL
select COL from #t2
union all
select COL from #t3





_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1332955
Posted Thursday, August 2, 2012 5:44 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, November 5, 2013 6:08 AM
Points: 1,079, Visits: 591
not confused @ all

What you don't know won't hurt you but what you know will make you plan to know better
Post #1339070
Posted Friday, August 3, 2012 5:23 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Saturday, May 31, 2014 9:19 PM
Points: 1,128, Visits: 1,162
great question, although I got it right, but I am glad i read the posts .Otherwise , I may have ended with wrong idea.

~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one
Post #1339741
Posted Wednesday, November 7, 2012 3:57 AM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Wednesday, February 20, 2013 1:45 AM
Points: 616, Visits: 97
oops...got it wrong..simple ques yet
Post #1381895
Posted Thursday, July 4, 2013 4:54 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, September 27, 2013 5:37 AM
Points: 306, Visits: 524
did`t knew that, thanx for the question








Neeraj Prasad Sharma
Sql Server Tutorials
Post #1470402
« Prev Topic | Next Topic »

Add to briefcase «««12345

Permissions Expand / Collapse