title: conditional sql query
body: <p>I have 2 tables where depending on a value on the first one, i have to select a column on the second one.</p>
  
  <p>Example</p>
  
  <p>table1</p>
  
  <pre><code>data1|data2|type
  P3   | C   |  R
  P1   | D   |  N
  P2   | C   |  R
  P1   | C   |  N
  P2   | D   |  R
  P3   | D   |  N
  </code></pre>
  
  <p>table2</p>
  
  <pre><code>name|revolution|nibs
  C   |repeat    |may
  D   |genocide  |fill
  </code></pre>
  
  <p>So, I want to get the values for data1 according to the type as this (R for revolution, N for nibs)</p>
  
  <p>Querying for P3:</p>
  
  <pre><code>name|value
  C   |repeat
  D   |fill
  </code></pre>
  
  <p>Querying for P1</p>
  
  <pre><code>name|value
  C   |may
  D   |fill
  </code></pre>
  
  <p>Thanks</p>