我有两张这样的表:
Name Index1 Name Index2
Muster1 1 Muster1 10
Muster2 2 Muster3 20
我想对这两个表进行总结,如下所示:
Name Index1 Index2
Muster1 1 10
Muster2 2 NULL
Muster3 NULL 20
如何在SQL中执行此操作?
答案 0 :(得分:4)
一个简单的FULL JOIN
会:
SELECT ISNULL(t1.Name,t2.Name) Name,
t1.Index1,
t2.Index2
FROM dbo.Table1 t1
FULL JOIN dbo.Table2 t2
ON t1.Name = t2.Name
;