为什么 Postgres 仅根据所选列选择不同的数据?
我正在运行两个不同的查询,每个都有两个工会在一个子查询中:
,
所以结构是:
SELECT *
FROM (subquery_1
UNION SELECT subquery_2)
现在,如果我在左侧执行查询,我得到了此结果:
但是,正确的查询返回此结果:
即使在任何查询中条件都没有改变,结果也有何不同,唯一的差异是一个子查询中选定的列的?
这是非常违反直觉的。
I'm running two different queries with two unions each inside a subquery:
So the structure is:
SELECT *
FROM (subquery_1
UNION SELECT subquery_2)
Now, if I perform the query on the left, I get this result:
However, the query on the right returns this result:
How are the results differing even though the conditions have not changed in either query, and the only difference was one of the selected columns in a subquery?
This is very counter-intuitive.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
运算符
UNION
删除重复行返回的结果集。从
SELECT
语句中删除列可能会产生重复行,如果删除的列存在,这些行就不会存在。请尝试使用
UNION ALL
,无论如何都会返回所有联合查询的行。查看简化的演示。
The operator
UNION
removes duplicate rows from the returned resultset.Removing a column from the
SELECT
statement may produce duplicate rows that would not exist if the removed column was there.Try
UNION ALL
instead, which will return in any case all the rows of the unioned queries.See a simplified demo.