title: How can I Pivot a table in DB2?
body: <p>I have table A, below, where for each unique id, there are three codes with some value.</p>
  
  <pre><code> ID    Code    Value
  ---------------------
   11       1       x
   11       2       y
   11       3       z
   12       1       p
   12       2       q
   12       3       r
   13       1       l
   13       2       m
   13       3       n
  </code></pre>
  
  <p>I have a second table B with format as below:</p>
  
  <pre><code>Id   Code1_Val   Code2_Val    Code3_Val
  </code></pre>
  
  <p>Here there is just one row for each unique id. I want to populate this second table B from first table A for each id from the first table. </p>
  
  <p>For the first table A above, the second table B should come out as:</p>
  
  <pre><code>Id   Code1_Val   Code2_Val    Code3_Val
  ---------------------------------------------
  11       x          y             z
  12       p          q             r
  13       l          m             n
  </code></pre>
  
  <p>How can I achieve this in a single SQL query?    </p>