title: MySQL JOIN ON, if column x is not null otherwise column y
body: <p>I would like to join my products table, while grabing the orders.</p>
  
  <p>I have a orders.product_id, which always have a value.</p>
  
  <p>But the case is, if <code>orders.bproduct_id</code> is not null, we should go by this product id instead at the </p>
  
  <pre><code>-&gt;join('products')-&gt;on('products.id', '=', 'dealsite_orders.product_id')
  </code></pre>
  
  <p>(I am using Kohana Query Builder, but I accept an query answer)</p>
  
  <p>How would I do this?</p>
  
  <p>When I do:</p>
  
  <pre><code>JOIN ON COALESCE(orders.bproduct_id,product_id)
  </code></pre>
  
  <p>It does not return any rows. After investigating I found out, its because it takes column value from bproduct_id even if its 0 ? </p>