-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
  • 499,602
  • 82
  • 638
  • 795
Krish
  • 1,518
  • 4
  • 30
  • 61

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
  • 36,607
  • 5
  • 19
  • 28
-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
  • 19
  • 1
  • 1
  • 4