title: SQL PIVOT Query, column based on value
body: <p>I'm stuck and do not seem to find the right foo for searching on Google for the answer.</p>
  
  <p>What I'm trying to do is to get the value from a column, the column is based on the value from another column:</p>
  
  <p>I have two tables:</p>
  
  <pre><code>pID | name | period
   0    abc      1
   1    def      2
   2    ghi      3
  </code></pre>
  
  <p>and</p>
  
  <pre><code>pID | p1 | p2 | p3
   0    10   20   30
   1    40   50   60
   2    70   80   90
  </code></pre>
  
  <p>I'd like to do a query that displays all pID's, their name, period and what value that period has. The output should be:</p>
  
  <pre><code>pID | name | period | NewVal
   0    abc      1        10
   1    def      2        50
   2    ghi      3        90
  </code></pre>
  
  <p>I hope it is clear what I'm trying to do!</p>
  
  <p>Thanks * 1000</p>