Tuesday, October 13, 2009

Convert ROWS into COLUMN

convert database Rows into Column its easy and simple.

If you have a table "master_stu" its having values like

stu_id stu_name class percentage
==== ====== === =======
1 vin sslc 88
1 vin hsc 90
2 swin sslc 75
2 swin hsc 89

you want to display above table into

stu_id stu_name class percentage class percentage
==== ====== === ======= === ========
1 vin sslc 88 hsc 90
2 swin sslc 75 hsc 89

just write a query like

select
tbl1.stu_id as stu_id, tbl1.stu_name,tbl1.class as class,tbl1.percentage as percentage,tbl2.class as class,tbl2.percentage as percentage
from
(select * from master_stu where class = 'sslc') as tbl1,
(select * from master_stu where class = 'hsc') as tbl2,
where
tbl1.stu_id=tbl2.stu_id

any query's mail me!

No comments: