0

I was wondering how using MySQL you would pivot a table from

+----------+----------+-------------+------------+
| table_id | other_id | description | expression |
+----------+----------+-------------+------------+
|        1 |        1 | blah        | blah       |
|        2 |        1 | meh         | meh        |
|        3 |        1 | example     | example    |
+----------+----------+-------------+------------+`

To a table being sorted using other_id to be like however without having expression and description limited to a specified number

+--------------+-------------+--------------+-------------+--------------+-------------+
| description1 | expression1 | description2 | expression2 | description3 | expression3 |
+--------------+-------------+--------------+-------------+--------------+-------------+
| blah         | blah        | meh          | meh         | example      | example     |
+--------------+-------------+--------------+-------------+--------------+-------------+`
Strawberry
  • 33,750
  • 13
  • 40
  • 57
Haytes
  • 91
  • 1
  • 11
  • 1
    It's generally best to handle issues of data display in application code – Strawberry Jul 04 '17 at 21:52
  • Particularly this kind of transformation would be a lot more effective in the application code, since there is no grouping in there. In mysql you would effectively have to query the data twice (once for determining the number of fields, second time to create the resultset). In the application logic you would have to query the data only once. – Shadow Jul 04 '17 at 21:58

0 Answers0