all groups > sql server odbc > march 2007 >
You're in the

sql server odbc

group:

Smart join when working with UNION


Smart join when working with UNION Jorgen [DK/2200]
3/5/2007 12:00:00 AM
sql server odbc:
Hi,

a have a query, which used UNION to collect data from 70 identical tables.

My problem is now that I need to join these data against another table with
a join. Is there a smart way of doing this ??

I want to avoid adding the join code for each of my 70 unions.

regards
jorgen

RE: Smart join when working with UNION RLoski
3/7/2007 2:34:11 PM
I find that I can do the following:
select a.*, b.*
from LookupTable b
right outer join
(select * from table1
union all
select * from table2
union all
select * from table3
union all
select * from table70) a
on a.LookupCol = b.LookupCol


--
Russel Loski, MCSD.Net


[quoted text, click to view]
AddThis Social Bookmark Button