I have a table like this:
COLA COLB COLC COLD 1 2 3 4 5 6 7 8
And I need SQL output like the following:
COLX COLY A 1 A 5 B 2 B 6 C 3 C 7 D 4 D 8
So I have four fixed columns, which have to be converted as rows.
This can be done with a UNION, with one SELECT per column:
select 'A' as COLX , COLA as COLY from yourtable union all select 'B' , COLB from yourtable union all select 'C' , COLC from yourtable union all select 'D' , COLD from yourtable order by COLX, COLY
Dig Deeper on Oracle and SQL
Related Q&A from Rudy Limeback
Read an example of an SQL case expression from our SQL expert Rudy Limeback. Continue Reading
Read SQL expert Rudy Limeback's advice for counting combinations in a table with SQL's GROUP BY clause Continue Reading
Read about the Mimer Validator, a tool used to verify your SQL code, in this tip from SQL expert Rudy Limeback. Continue Reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.