Unpivot Function
Does MySQL have an UNPIVOT function like SQL Server? I know I can do the UNION approach to split everything apart but the problem is I have 241 columns that I'm trying to UNPIVOT into rows so the UNION approach is a little cumbersome.
Current_table:
id token column1 column2 column3
1 AAA 1234 abcd mnop
2 BBB 5678 efgh qrst
3 CCC 9101 ijkl uvwx
Desired output:
id token columns
1 AAA 1234
1 AAA abcd
1 AAA mnop
2 BBB 5678
2 BBB efgh
2 BBB qrst
3 CCC 9101
3 CCC ijkl
3 CCC uvwx
Solution using UNION:
SELECT id
,token
,column1 as columns
from Current_table
UNION
SELECT id
,token
,column2 as columns
from Current_table
UNION
SELECT id
,token
,column3 as columns
from Current_table
If anyone has a more elegant way to unpivot my columns into rows I'd really appreciate any insight.
thanks,
rob
Subject
Written By
Posted
Unpivot Function
August 07, 2010 12:28PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.