select id=identity(int,1,1),col1,col2=sum(col2) into #t1 from table1 a group by col1
go
select id=identity(int,1,1),col1 as col3,col4=sum(col2) into #t2 from table2 group by col1
go
select a.col1,a.col2,b.col3,b.col4 from #t1 a left join #t2 b
on a.id=b.id
drop table #t1,#t2
go
select id=identity(int,1,1),col1,col2=sum(col2) into #t1 from table1 a group by col1
go
select id=identity(int,1,1),col1 as col3,col4=sum(col2) into #t2 from table2 group by col1
go
select a.col1,a.col2,b.col3,b.col4 from #t1 a left join #t2 b
on a.id=b.id
go
create talbe #t1 (a identity(1,1) int,b char(10),c int)
create talbe #t2 (a identity(1,1) int,b char(10),c int)
insert into #t1 select col1,sum(col2) from table1 group by col1 order by col1
insert into #t2 select col1,sum(col2) from table2 group by col1 order by col1
select #t1.b as col1,#t1.c as col2,#t2.b as col3,#t2.c as col4 from #t1 left join #t2 on
#t1.a=#t2.a