title: IF condition in INNER JOIN SQL Query
body: <p>I have a problem in writing sql query. Here is the illustration about my problem.
  I have 2 tables in the database as follows :</p>
  
  <pre><code>| Table A    |          | Table B     |
  
  | idTableA   |          | idTableB    |
  | idPriority |          | idReference |  
  </code></pre>
  
  <p>Those tables above are related. The <strong>idReference</strong> in <strong>Table B</strong> is referring to <strong>idPriority</strong> in <strong>Table A</strong>. <strong>BUT</strong> if the value of the <strong>idPriority</strong> is <strong>NULL</strong>, then the <strong>idReference</strong> should be referring to <strong>idTableA</strong>. Hope you guys get the illustration and can help me working with this problem. Thx in advance. </p>