Sandy_Unknown
Sandy_Unknown

Reputation: 41

Merge multiple columns into single column using sql

I have data into below format :

 Col1     Col2     Col3      Col4
 ABC      12         34        45

I want output as below :

Col1    Col2

ABC      12 
ABC      34
ABC      45

Upvotes: 1

Views: 836

Answers (2)

Niederee
Niederee

Reputation: 4295

If you need to dynamically generate the sql consider the following:

select 'union all select col1, '||  column_name || ' as col2 from ' || table_name
from _v_odbc_columns1
where table_name = '<table name>'
and ordinal_position >=2
order by ordinal_position

Upvotes: 1

Jens
Jens

Reputation: 69440

You can use union:

select col1, col2
union all
select col1, col3
union all
select col1, col4

Upvotes: 1

Related Questions