title: MySQL add condition to a query only when it is true
body: <p>I want to apply the <code>gla.last_importation_date</code> to my query only if the date of importation for the transaction falls between the <code>start_date</code> and <code>end_date</code>. It should not be affecting the query if the date doesn't fall in between that date range. Below is my query</p>
  
  <pre><code>SELECT 
    gla.identifier,gla.name, gla.slug, gla.real_depth, gla.balance, 
    SUM(je.debit_record) debits, SUM(je.credit_record) credits
  FROM general_ledger_accounts gla 
  LEFT JOIN 
    (
     SELECT li.debit_record, li.credit_record, jle.transaction_date, li.general_ledger_account_id 
       FROM line_items li 
       JOIN journal_entries jle 
         ON jle.id = li.journal_entry_id 
       WHERE jle.transaction_date BETWEEN :START_DATE AND :END_DATE 
     ) je 
  ON je.general_ledger_account_id = gla.id 
  WHERE 
       gla.type_letter IN ('I', 'E') 
  OR 
  (gla.last_importation_date BETWEEN :START_DATE AND :END_DATE) 
  GROUP BY gla.identifier, gla.name, gla.slug, gla.real_depth, gla.balance, gla.imported_balance;
  </code></pre>