title: conditional join in sql
body: <p>I want to join two tables on a field that depends on a certain condition:</p>
  
  <pre><code>select * from table1 join table2 on table1.$variable = table2.id
  </code></pre>
  
  <p>with </p>
  
  <pre><code>$variable = table1.id1 is not null ? table1.id1 : table1.id2
  </code></pre>
  
  <p>can I do this?</p>