sql - 在不使用 union all 的情况下获取 union all 的输出
问题描述
我遇到了一种情况,可以在不使用union
. 我能行。但我无法做到“联合所有”。我的意思是我必须找出 2 个表的输出,包括重复而不使用union all
. 有什么办法吗?
table A has x column and values 1,2,3
and
table B has x column and values 3,4,5
select x from A union select x from B;
o/p 1,2,3,4,5
select x from A union all select x from B;
o/p should be 1,2,3,3,4,5,6(not necessarily in order)
Union
输出我可以通过下面的查询来实现
select nvl(a.x,b.x) output from A full outer join B on A.x=b.X order by output;
但我union all
不能不使用 oracle inbuilt union all
。
解决方案
你离你的答案太近了。
对于union
,您使用了以下查询,其中您在列 x 上有一个联接:
select nvl(a.x,b.x) output from A full outer join B on A.x=b.X order by output;
对于union all
,您可以使用永远无法满足的连接条件。它将生成与 相同的输出union all
。
因此,您必须使用以下查询:
select nvl(a.x,b.x) output from A full outer join B on 1=2 order by output;
干杯!!
推荐阅读
- swift - SwiftUI 列表禁用单元格按下
- python - Python 语法:从三元表达式中的函数返回值解包多个变量会产生意外结果
- jenkins - 无法在 Ubuntu 18.04 上的 Jenkins 上安装插件
- javascript - 上传视频时如何将视频(mp4)文件转换为音频(mp3)文件
- python - 在 Python 中将 TensorFlow 模型(集成)保存到一个泡菜文件,而不是多个泡菜
- python-3.x - 错误 - 'English' 对象没有属性 'add_label'
- java - IntelliJ - 无法解析符号“数组”
- xilinx - vhdl 延迟线实现属性
- python - 我对这段代码使用套接字接收多播的结论是否合理?
- c - STM32H7 SPI时钟频率,不随不同的BaudratePrescaler值变化