title: DB QUERY IN ORACLE
body: <pre><code>SELECT 
      BILLS.* 
  FROM 
      BATELCO_BILLS_S BILLS 
  INNER JOIN 
  (
      SELECT 
           BTL_BILL_I_NUMBER, 
           MAX(R_MODIFY_DATE) AS MAXDATETIME 
      FROM 
          BATELCO_BILLS_S  
      GROUP BY 
           BTL_BILL_I_NUMBER
  ) GROUPEDBILLS
      ON BILLS.BTL_BILL_I_NUMBER = GROUPEDBILLS.BTL_BILL_I_NUMBER AND
         BILLS.R_MODIFY_DATE = GROUPEDBILLS.MAXDATETIME 
  WHERE 
      (BILLS.BTL_BILL_I_CPR = :B3 OR BILLS.BTL_BILL_C_CPR = :B3) AND
      (TO_DATE(BTL_BILL_I_DATE) BETWEEN TO_DATE(:B2, 'dd/mm/yyyy') AND
       TO_DATE(:B1, 'dd/mm/yyyy') OR
       TO_DATE(BTL_BILL_C_DATE) BETWEEN TO_DATE(:B2, 'dd/mm/yyyy') AND
       TO_DATE(:B1, 'dd/mm/yyyy'))
  </code></pre>
  
  <p>Please help to get optimize the query by avoiding the join so that GROUP BY is required.</p>
  
  <p>AVOID DUPLICATE BTL_BILL_I_NUMBER AND FETCH THE RESULTS.</p>