Rearranging sql query table (Oracle)

Viewed 16

when I have a sql query (after pivot etc) which look like this

ID    Value1   Value2   Value3   Value4
Name1 N1V1     N1V2     N1V3     N1V4
Name2 N2V1     N2V2     N2V3     N2V4

And this table should be projected into this (for each native row creating 2 new rows):

ID    Value1/2  Value3/4
Name1  N1V1      N1V3
Name1  N1V2      N1V4
Name2  N2V1      N2V3
Name2  N2V2      N2V4

How shall I do this?

Thanks a lot for your help!

Kind regards, Markus

1 Answers

There are too few input data to guess the result desired. Are all values unique? Do you need duplicates? But as a first approach, try to use this one:

SELECT id, value1 as value_1_2, value3 as value_3_4 
FROM table1 
union all
SELECT id, value2, value4 FROM table1
order by 1;
Related