title: Mysql query to dynamically convert rows to columns on the basis of two columns
body: <p>I have followed a <a href="https://stackoverflow.com/questions/14834290/mysql-query-to-dynamically-convert-rows-to-columns">question</a> here to use a Mysql query to dynamically convert rows to columns. This works fine, but i need to convert this on basis of two columns, </p>
  
  <p>The query mentioned in above link works for a single column "data", but i want to work for two columns which are "data" and "price".</p>
  
  <p>i have added an example here,</p>
  
  <p>Given a table A, which look like</p>
  
  <pre><code>Table A
  
  |  id|order|data|item|Price|
  -----+-----+----------------
  |   1|    1|   P| 1  | 50  |
  |   1|    1|   P| 2  | 60  |
  |   1|    1|   P| 3  | 70  |
  |   1|    2|   Q| 1  | 50  |
  |   1|    2|   Q| 2  | 60  |
  |   1|    2|   Q| 3  | 70  |
  |   2|    1|   P| 1  | 50  |
  |   2|    1|   P| 2  | 60  |
  |   2|    1|   P| 4  | 80  |
  |   2|    3|   S| 1  | 50  |
  |   2|    3|   S| 2  | 60  |
  |   2|    3|   S| 4  | 80  |
  </code></pre>
  
  <p>I like to write a query that looks like the following:</p>
  
  <pre><code>Result Table
  
  |  id|order1|order2|order3|item1|item2|item3|item4|
  -----+-----+---------------------------------------
  |   1|    P |    Q |      | 50  | 60  | 70  |     |
  |   2|    P |      |    S | 50  | 60  |     | 80  |
  </code></pre>
  
  <p>I have tried to create two different queries and then a join to achieve this, but that may not be a good solution. Can any one suggest a solution same like mentioned in the link above.</p>
  
  <p>Thanks</p>