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 Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, May 17, 2013 1:36 AM
Points: 99, Visits: 28
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, February 14, 2013 2:45 AM
Points: 285, Visits: 62
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


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Yesterday @ 1:17 PM
Points: 8,641, Visits: 8,273
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
Post #1332955
Posted Thursday, August 02, 2012 5:44 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, March 27, 2013 9:02 AM
Points: 1,046, Visits: 573
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 03, 2012 5:23 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Saturday, May 18, 2013 6:46 PM
Points: 1,074, Visits: 1,076
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 07, 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
« Prev Topic | Next Topic »

Add to briefcase «««12345

Permissions Expand / Collapse