Monday, May 21, 2012

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




union operation in mysql


1. NUMBER OF COLUMN IS SAME 

2. DATA TYPE IS SAME BUT NOT NECESSARY IN MYSQL 

SELECT *   FROM `table1`

 UNION

 SELECT *  FROM `table2`  LIMIT 0 , 30

No comments:

Post a Comment

If you Satisfied , Please Leave a comment