title: Adding values to table1 column based on dynamic conditions from table2
body: <p>I have 2 tables, table1 and table2 and I am trying to add a column to table2 based on values <code>a</code> from table1 and some sort of dynamic conditional statement on <code>c</code> from table2 to get <code>e</code> in table3. This has to be dynamic because table1 will change in both row count and values in columns a and b.</p>
  <p>I am not sure how to approach this problem and any help would be appreciated.</p>
  <pre><code>table1
   a   |  b
  -----+-----
     0 | 1
     5 | 2
    10 | 3
    20 | 4
  </code></pre>
  <pre><code>table2
   c   |  d
  -----+-----
    2 | 100  
    3 | 101
    5 | 102
    7 | 103
   11 | 104
   13 | 105
   17 | 106
   19 | 107
   23 | 108
  </code></pre>
  <pre><code>table3
   c   |  d   |   e
  -----+------+------
    2 | 100  | 1
    3 | 101  | 1
    5 | 102  | 2
    7 | 103  | 2
   11 | 104  | 3
   13 | 105  | 3
   17 | 106  | 3
   19 | 107  | 3
   23 | 108  | 4
  </code></pre>