SQL合并-在结果输出中填充合并值的其他方法?

SQL合并-在结果输出中填充合并值的其他方法?,sql,sas,full-outer-join,Sql,Sas,Full Outer Join,我想把两张桌子连接起来,就像 have1 key ... a ... b ... c ... have2 key ... a ... c ... d ... 并获得像这样的输出 want key ... a ... b ... c ... d ... 我知道 create table want as select coalesce(a.key, b.key) as key, ..., from have1 a full join have

我想把两张桌子连接起来,就像

have1
key ...
a   ...
b   ...
c   ...

have2
key ...
a   ...
c   ...
d   ...
并获得像这样的输出

want
key ...
a   ...
b   ...
c   ...
d   ...
我知道

create table want as 
  select coalesce(a.key, b.key) as key, ..., 
  from have1 a full join have2 b 
  on a.key=b.key;
将给我输出,但有其他选择吗?我希望有更简洁易读的代码,加入3或4个条件似乎需要大量文本才能实现所需的输出,例如SAS数据步骤。

您可以使用union all:


在许多数据库中,可以使用以下语法消除连接列的歧义:


联合运营者就是你想要的。它会自动删除重复项

data have1;
input key $;
cards;
a
b
c
;;;;
run;

data have2;
input key $;
cards;
a
b 
d
;;;;
run;

proc sql;
create table want as 
select * from 
have1 union select * from have2;
quit;

proc print data=want;
run;

关键变量是唯一的公共变量吗?你试过自然加入吗?
create table want as 
select key, ..., 
from have1 a 
full join have2 b using (key)
data have1;
input key $;
cards;
a
b
c
;;;;
run;

data have2;
input key $;
cards;
a
b 
d
;;;;
run;

proc sql;
create table want as 
select * from 
have1 union select * from have2;
quit;

proc print data=want;
run;