title: How can i do a condition join with IF statement
body: <p>How would you do a inner join on a table where i need to filter the status, but on one of the status value, i need to perform an additional date comparison check on SQL phpmyadmin.</p>
  <p>i have the following:</p>
  <p>ex.</p>
  <pre><code>INNER JOIN orders backup_orders
      ON backup_orders.bc_id = product_sold.order_id
      AND backup_orders.status_id NOT IN (0, 1, 4, 6, 13, 14)
      AND CONVERT_TZ( STR_TO_DATE( backup_orders.date_modified, &quot;%a, %d %b %Y %T&quot; ) , &quot;GMT&quot;, &quot;America/Chicago&quot; )
          &gt;= CONVERT_TZ(STR_TO_DATE(:previous_week_start, &quot;%a, %d %b %Y %T&quot;) , &quot;GMT&quot;, &quot;America/Chicago&quot;)
  </code></pre>
  <p>This only gets me the record where the order is cancelled and it was cancelled after the previous_week_start. I want all the records but if the status is 5 which is cancelled, perform the date comparison and if it was cancelled after the date then add it to the result.</p>
  <p>#Edited:</p>
  <pre><code>AND(backup_orders.status_id NOT IN (0,1,4,6,13,14) OR (backup_orders.status_id = 5 AND CONVERT_TZ( STR_TO_DATE( backup_orders.date_modified, '%a, %d %b %Y %T' ) , 'GMT', 'America/Chicago' ) &gt;= CONVERT_TZ(STR_TO_DATE(&quot;Thu, 11 Mar 2021 22:00:00 +0000&quot;, '%a, %d %b %Y %T') , &quot;GMT&quot;, &quot;America/Chicago&quot;)))
  </code></pre>