是否存在类似于联合的合并的句法快捷方式?

时间:2017-06-16 14:52:04

标签: sql

我要做的是:

select 
A.Fuzz
,A.Fizz
,B.Whiz
 from A
left outer join B
on A.Fuzzy B=Wuzzy

替换:

select 
A.Fuzz
,A.Fizz
,B.Whiz
 from A
left outer join B
on A.Fuzzy B=Wuzzy
UNION ALL
select 
B.wuzz
,A.Fizz
,B.Whiz
 from A
left outer join B
on A.Fuzzy B=Wuzzy

1 个答案:

答案 0 :(得分:1)

可能这是“接近”您的想法(在MSSQL上完成)?请在每个问题中发布样本数据,预期结果等。

CREATE TABLE A (ID INT, DESC_A VARCHAR(10));
INSERT INTO A VALUES (1,'A');
INSERT INTO A VALUES (2,'B');

CREATE TABLE B (ID INT, DESC_B VARCHAR(10));
INSERT INTO B VALUES (2,'Z');
INSERT INTO B VALUES (3,'Y');

SELECT COALESCE(A.ID, B.ID) AS ID
, A.DESC_A
, B.DESC_B
FROM A
FULL JOIN B ON A.ID = B.ID

输出:

ID  DESC_A  DESC_B
1   A   NULL
2   B   Z
3   NULL    Y