0

i am searching since a while for a performant MySQL Query solution. Hope someone could help me.

My Table looks like that:

values_table
___________________________________
| id | col | row | value          |
-----------------------------------
| 1  | 1   | 1   | Test1          |
| 2  | 2   | 1   | Test2          |
| 3  | 1   | 2   | Test3          |
| 3  | 3   | 2   | Test4          |
| 3  | 4   | 3   | Test5          |
-----------------------------------

And i want to reach following result:

_________________________________
| col_1 | col_2 | col_3 | col_4 |
---------------------------------
| Test1 | Test2 | null  | null  |
| Test3 | null  | Test4 | null  |
| null  | null  | null  | Test5 |
---------------------------------

I dont know how many columns it could be so it had to be dynamicly and not like static left joins. Is something like this possible?

Would be so thankfuly if someone could help me!

Thank you!

Rick James
  • 135,179
  • 13
  • 127
  • 222
  • 1
    Answers to the duplicate question include both static and dynamic number of columns. However, the resulting query is unlikely to be performant and you may be a lot better off if you did this transformation in the application code. – Shadow Jul 13 '20 at 14:15
  • Pivot: http://mysql.rjweb.org/doc.php/pivot – Rick James Jul 13 '20 at 23:14

0 Answers0