1

I have a dynamic attributes table in mysql

attributes
----------
attribute_id    description
1               Code produit
2               Code millesime  
3               Titre du produit
...             ....

And a products table:

products
--------
product_id  attribute_id    value
1020        1               xyz
1020        2               zyt
1020        3               UUU
....        ...             ....

I need an sql statement to pivot the products table so that I get the following:

products_pivot
--------------

product_id  Code produit    Code millesime  Titre du produit    ...
1020        xyz             zyt             UUU                 ...

Is there a simple way to achieve this in mysql, given that the number of columns generated would be dynamic?

And if so, I was also wondering what the performance would be for let's say 1000 products, each product containing about 100 attributes. (That means 100000 records in the products table...)

Arbiz
  • 172
  • 1
  • 5
  • 12
  • Possible duplicate of [Converting rows with too many values to columns](http://stackoverflow.com/questions/37424842/converting-rows-with-too-many-values-to-columns) – Uueerdo May 26 '16 at 22:13
  • Possible duplicate of [MySQL pivot table](http://stackoverflow.com/questions/7674786/mysql-pivot-table) – Alex May 27 '16 at 01:43
  • 1
    Q: *Is there a simple way* A: No, there is no simple way to achieve that – Alex May 27 '16 at 01:44

0 Answers0