Toad World® Forums

I am having a requirement of retrieving the data in the below mentioned format, please help


#1

Data available in the DB:

Table 1
Column1
Column2
Ram
1
Sam
2
Zam
3
Cam
4
Dam
5

Data to be retrieved as follows

Column
Ram
1
Sam
2
Zam
3
Cam
4
Dam
5
please help me over this senario…


#2

Should perhaps be solved by analytic function but here is a simple solution:

select c from table1 t,

(select column1,column2,column1 as c

from table1

union all

select column1,column2,to_char(column2)

from table1 ) t2

where t2.column1=t.column1

and t2.column2=t.column2

order by t.column2, c desc;


#3

Or even better:

select c

from (select column1, to_char(column2) col2 from table1)

unpivot

(

c

for node in (column1,col2)

);