从两个表中获取所有数据

时间:2015-11-18 10:47:08

标签: sql-server

我有以下表格

Tbl_T1
PRODUCT VALUE

A       10
C       30

Tb1_T2
PRODUCT VALUE

B       20
C       30

我正在寻找输出

PRODUCT VALUE1  VALUE2
A       10       0
B        0      20
C       30      30

1 个答案:

答案 0 :(得分:0)

它被称为全外连接

select coalesce(t1.product, t2.product) as pr, 
       coalesce(t1.value, 0) as v1, 
       coalesce(t2.value, 0) as v2
from t1
full outer join t2 on t1.product = t2.product