title: Reformatting (reshaping) data table from long to wide using MySQL
body: <p>New to MySQL and trying to carry something over from R. </p>
  
  <p>I have a data table with two columns, similar to the following, with a level-2 id and a nested id: </p>
  
  <pre><code>level2id | nestedid |
  1        | 1        |
  1        | 2        |
  1        | 3        |
  2        | 1        |
  2        | 2        |
  ...
  </code></pre>
  
  <p>I want to restructure the data using MYSql in a new table like this: </p>
  
  <pre><code>level2id | nestedid1 | nestedid2 | nestedid3 |
  1        | 1         | 2         | 3         |
  2        | 1         | 2         |           |
  ...
  </code></pre>
  
  <p>This is so that I can later perform joins to extract information on the nested ids to create aggregate values for variables that relate to the level2 id. Trivial to do in R using reshape for "time-varying" data, but can't find an obvious solution to this particular format (i.e. where the data are not organized in terms of attribute names and attribute values in columns. Thanks in advance! </p>