Yeah, Like I said it will return two records. UNION simply combines the resultsets of two (or more) statements into one resultset. You should probally use a join ... but your ID's are different. Whats the relationship between tbl_1 and tbl_2?
-Greg
-----Original Message-----
From: aaron [mailto:[Email Address Removed] Friday, May 30, 2003 10:32 AM
To: LazyDBA.com Discussion
Subject: RE: Combine two statements ...
That sort of worked - but I get the results from the first select, then
under it the results from the second
1,2,3,,,,
,,,aa,bb,cc,dd,ee
... Ideally I would like to have:
Select a, b, c
From tbl1
Where id = 10
...returns...
1,2,3
select d, e, f, g
From tbl2
Where id = 11
...returns...
Aa,bb,cc,dd,ee
Then when they are unioned the results would be . . . .
1,2,3,aa,bb,cc,dd,ee
-----Original Message-----
From: Greg [mailto:[Email Address Removed]
Sent: May 30, 2003 11:22 AM
To: LazyDBA.com Discussion
Use place holders... (0 for number cols, '' or something for char's)...
Select a, b, c, 0, 0, 0, 0, 0, 0, 0 from tbl_1 Union Select 0, 0, 0, x,
y, z, aa, bb, cc, dd from tbl_2
Note: if tbl_1 has One record and tbl_2 has one record this statement will
return 2 records...
-Greg
-----Original Message-----
From: aaron [mailto:[Email Address Removed] Friday, May 30, 2003 10:04 AM
To: LazyDBA.com Discussion
Subject: Combine two statements ...
How can I combine two select statements that do not have an equal number of
expressions???
Select a, b, c from tbl_1
Union
Select x, y, z, aa, bb, cc, dd from tbl_2
Then.. The desired results would be:
A, b, c, x, y, z, aa, bb, cc, dd
:)
---------------------------------------------------------------------
TO REPLY TO EVERBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY To
unsubscribe, e-mail: mssqldba-[Email Address Removed] For additional
commands, e-mail: mssqldba-[Email Address Removed] REPLY TO EVERBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY To
unsubscribe, e-mail: mssqldba-[Email Address Removed] For additional
commands, e-mail: mssqldba-[Email Address Removed] REPLY TO EVERBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY
To unsubscribe, e-mail: mssqldba-[Email Address Removed] additional commands, e-mail: mssqldba-[Email Address Removed]MS Sql Server LazyDBA home page