Sql 如何从两个值相同且为null的列中获取单个列?
您好,我如何从postgresql中的两列中获取单列,因为我的列输出是:Sql 如何从两个值相同且为null的列中获取单个列?,sql,postgresql-8.2,Sql,Postgresql 8.2,您好,我如何从postgresql中的两列中获取单列,因为我的列输出是: Column 1 Column 2 a a b c c 或 应该得到如下输出 column a b c 尝试了连接,但它连接了表,因为我不想连接列您可能应该研究一下SQL,至于您的问题,我相信union和distinct可以解决问题 select distinct(foo.foo) from( select column1 as
Column 1 Column 2
a a
b
c c
或
应该得到如下输出
column
a
b
c
尝试了连接,但它连接了表,因为我不想连接列您可能应该研究一下SQL,至于您的问题,我相信
union
和distinct
可以解决问题
select distinct(foo.foo) from(
select column1 as foo from your_table where column1 is not null
union
select column2 as foo from your_table where column2 is not null) as foo;
看
select distinct(foo.foo) from(
select column1 as foo from your_table where column1 is not null
union
select column2 as foo from your_table where column2 is not null) as foo;