Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何从两个值相同且为null的列中获取单个列?_Sql_Postgresql 8.2 - Fatal编程技术网

Sql 如何从两个值相同且为null的列中获取单个列?

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

您好,我如何从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 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;