sql to combine two unrelated tables into one -
i have tables
table1
col1 col2 b c d and table2
mycol1 mycol2 e f g h j k l i want combine 2 tables, have no common field 1 table looking like:
table 3
col1 col2 mycol1 mycol2 b e f c d g h null null j null null k l ie, putting 2 tables side side.
i'm stuck! please help!
get row number each row in each table, full join using row numbers:
with cte1 ( select row_number() over(order col1) rownum, * table1 ), cte2 ( select row_number() on (order mycol1) rownum, * table2 ) select col1, col2, mycol1, mycol2 cte1 full join cte2 on cte1.rownum = cte2.rownum this assuming sql server >= 2005.
Comments
Post a Comment