首页 > 解决方案 > 无法在 Postgres 中执行联合

问题描述

对于某些表t,我想做以下查询:

select 'X' as "Indicator" from t limit 1
union 
select 'Y' as "Indicator" from t limit 1 

我的期望:

Indicator
X
Y

我得到什么:ERROR: syntax error at or near "union"

为什么会这样?列名相同,在这两种情况下只有一列。怎么了?

标签: sqlpostgresqlunion

解决方案


如果你想要两个结果,就像这样

(select 'X' as "Indicator" from t limit 1)
union 
(select 'Y' as "Indicator" from t limit 1)

推荐阅读