display column values as rows in mysql query

id c1 c2 c3
1 10 20 30
2 15 50 24

SELECT ‘C1’ as colname, c1 as colval FROM `tablename`
UNION ALL SELECT ‘C2’ as colname , c2 AS colval FROM `tablename`
UNION ALL SELECT ‘C3’ as colname , c3 AS colval FROM `tablename`

C1 10
c1 15
c2 20
c2 50
c3 30
c3 24

display column values as rows wise

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s