Tuesday, March 27, 2012

Create a table from select Queries.

Hi,

I wanted to know a query which will create a final result table from a combination of select queries.

The select query is like :
1. select col1 , col2 , null from table1
2. select null , col2 , null from table2
3. select null , null , col3 from table 3.

null are inserted as i wanted a single select query which will merge all the columns from all the tables and finally create a result table.

Thanks in advance.select *
into resulttable
from (
select col1 as col1,
col2 as col2,
null as col3
from table1
union all
select null ,
col2 ,
null
from table2
union all
select null ,
null ,
col3
from table3
) as tm

No comments:

Post a Comment