title: IF statement in mysql JOIN - Adding multiple conditions if condition success
body: <p>Here is the case:-</p>
  
  <p>I want to join 2 tables. Lets say table <code>a</code> and <code>b</code></p>
  
  <pre><code>SELECT * 
  FROM a 
  JOIN b ON a.id = b.id AND b.status = '1' 
  </code></pre>
  
  <p>Here is the problem:</p>
  
  <pre><code>b.status = '1'
  </code></pre>
  
  <p>should only be added when </p>
  
  <pre><code>b.stage in (1, 3, 5, 6, 8)
  </code></pre>
  
  <p>How can I add such condition in <code>ON</code> clause ?</p>
  
  <p>Like </p>
  
  <pre><code>ON a.id = b.id 
  CASE
     IF (b.stage in (1, 3, 5, 6, 8))
  THEN
     AND b.status = '1'
  END
  </code></pre>