title: mysql JOIN ON IF()?
body: <p>I am trying to use sql such as this:</p>
  
  <pre><code>SELECT t.*, t2.* FROM templates t
  LEFT JOIN IF(t.t_type = 0,'templates_email',
  IF(t.t_type = 1,'templates_sms','templates_fax')) t2
  ON t.t_id = t2.t_id;
  </code></pre>
  
  <p>Is it possible to do something like that?</p>
  
  <p>basically I want to join on one of three tables based on the value from the row.</p>
  
  <p>Is this recommended if it is possible?</p>
  
  <p><hr />
  <strong>update</strong><br />
  So, </p>
  
  <p>basically the <code>templates</code> table is the table that contains all the information that every template must have, eg name, id, description</p>
  
  <p>then you have the <code>templates_x</code> tables these tables contain the fields that are unique to each template type.<br>
  (There are quite a few and having a single table with null fields for those not applicable is not practical).</p>
  
  <p>The tables are called <code>templates_x</code> however the appropriate x is stored in the templates table as an int flag.</p>
  
  <p>The join between the <code>templates_x</code> tables and the <code>templates</code> table is through the <code>t_id</code>.</p>
  
  <p>So what do you suggest?</p>