how to get single column from two columns having same value and null?

25 Views Asked by At

Hi how do i get single column from two columns in postgresql as my column outputs are:

Column 1     Column 2
a            a     
b              
c            c

or

column 1    column 2
a            a
             b
c            c

should get output as below

column
a
b
c

Tried concatenating but it joins table as i don't want to join columns

1

There are 1 best solutions below

0
Hatik On

You should probably research SQL a bit, as for your question I believe union with distinct will do the job

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;

See sqlfiddle