我有两张桌子 表A:
Fruit Number
Apple 7235
Plum 1284
Pear 8932
Orange 2839
表B:
Fruit Number
Apple 7235
Apple 3893
Plum 1284
Pear 8932
Orange 2839
Orange 4732
我希望查询的最终结果是获取表格不相同的列。例如New TableC:
Fruit Number
Apple 3893
Orange 4732
我尝试进行连接但是连接仅在第一次出现记录时进行。我怎样才能达到上述预期效果。
答案 0 :(得分:0)
使用full join
可以让你在任何一方都缺少行。
select fruit,coalesce(num1,num2) as number
from (select coalesce(a.fruit,b.fruit) as fruit,a.number as num1,b.number as num2
from a
full join b on a.fruit=b.fruit and a.number=b.number
where a.number is null or b.number is null
) t