I am writing a query to get result from a table "tbl_meta" having 3 columns as ID,attr_name,attr_value.
Table structure is like 2nd column is name of attribute and 3rd column is its value like below
ID attr_name attr_value
1 name abc
2 address aaa
3 age 25
So,when I use "select * from tbl_meta where ID = 10" , I got result like as it is as shown above but I need result with columns in a single row like below:
col1 col2 col3 col4 col5 col6
name abc address aaa age 25
how can I do this using mysql?
NOTE
I have tried solutions given @ MySQL - Rows to Columns and MySQL pivot row into dynamic number of columns but it's not how I am expecting. When I tried like
SELECT
case when attr_name = 'name' then attr_value end as name ,
case when attr_name = 'address' then attr_value end as address,
case when attr_name = 'age' then attr_value end as agep,
FROM tbl_meta
where ID = 10
I am getting output as :
name address age
abc NULL NULL
NULL aaa NULL
NULL NULL 25
instead can't I get like
name address age
abc aaa 25
from above table.