create table table1 (colA int, colB int, colC int, colD varchar(50))
Insert into table1 values(1, 4, 7, 'a') , (2, 5, 8, 'b'), (3, 6, 9, 'c')
create table table2(colA int, colB int, colC int, colE varchar(50))
Insert into table2 values(1, 4, 7, 'd') , (4, 5, 8, 'e')
Select COALESCE(a.ColA,b.Cola) Cola,
COALESCE(a.Colb,b.Colb) Colb,
COALESCE(a.Colc,b.Colc) Colc,
a.ColD,
b.ColE ColE
from table1 a full OUTER JOIN table2 b ON a.colA=b.cola
drop table table1
drop table table2
/*
Cola Colb Colc ColD ColE
1 4 7 a d
2 5 8 b NULL
3 6 9 c NULL
4 5 8 NULL e
*/
Thursday, August 1, 2013
Query Help Merging 2 Tables
Labels:
big loop My VS C#
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment