Combining two tables without any common field

Kirthiga
Posted by Kirthiga under Sql Server category on | Points: 40 | Views : 790
create table Table1 (C1 int)
insert into Table1 values(1)
insert into Table1 values(2)
insert into Table1 values(3)
insert into Table1 values(4)

create table Table2 (C2 int)
insert into Table2 values(5)
insert into Table2 values(6)
insert into Table2 values(7)
insert into Table2 values(8)

;with T1 as
(select C1,ROW_NUMBER()over(order by C1)Rn from Table1),
T2 as
(select C2,ROW_NUMBER()over(order by C2)Rn from Table2)
select T1.C1,T2.C2 from T1 join T2 on T1.Rn=T2.Rn

Comments or Responses

Login to post response