Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Selecting from a union join?

Author  Topic 

kleinmi
Starting Member

9 Posts

Posted - 2002-07-10 : 11:00:59
How can I select from a union join?

ex.

select *
from
(
(select * from table1) union all (select * from table2)
)

This doesn't work, but this is the basic logic behind what i'm trying to do

Thanks for any help!
Michael


MakeYourDaddyProud

184 Posts

Posted - 2002-07-10 : 11:05:06
quote:

select *
from
(
(select * from table1) union all (select * from table2)
)



... you are missing a correlation name off the SQL

Try...

select *
from
(
select * from table1
union all
select * from table2
) as Table1_2

Remember that the number of columns and datatype for table1 and table2 must match exactly



Daniel Small MIAP
www.danielsmall.com IT Factoring
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-07-10 : 11:06:19
Why not:

select * from table1
union all
select * from table2


You don't need to make a subquery out of it.

FYI, if you do use a subquery, you need to alias it with a name:

select * from (select * from table1 union all select * from table2) AS subQuery



Edited by - robvolk on 07/10/2002 11:07:01
Go to Top of Page

MakeYourDaddyProud

184 Posts

Posted - 2002-07-11 : 03:40:51
Making a subquery of it might be required if the developer wanted to join to the consildated SELECTs as a whole, although performance and table scanning might be an issue.

Daniel Small MIAP
www.danielsmall.com IT Factoring
Go to Top of Page
   

- Advertisement -