-1

I have one table which contains multiple param name and param value.

enter image description here

enter image description here

I would like to select the records in such a way that all param name should come as header/column name and param values should get as multiple rows.

enter image description here

How to do it in mysql ?

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
Krish
  • 1,804
  • 7
  • 37
  • 65

2 Answers2

1

use case when expression

select max(case  when param_name='school' then param_value end) as school,
max(case  when param_name='bus' then param_value end) as bus
from tablename group by test2_id
Fahmi
  • 37,315
  • 5
  • 22
  • 31
-1

fa06's answer is probably the best way to make this type of selection if there is a known, static set of param_name values, for which case you can just hardcode them in. If not, you'd probably want to first select unique param_name entries and then a selection of the param_values for each different param_name.

Anders Juengst
  • 39
  • 1
  • 1
  • 4