title: Oracle: How to use Group by and Max(datetime) each record no duplication
body: <p>I want to Group by <code>Max(Datetime)</code> in each record,
  but my query has duplicate records. I don't want duplicate records.</p>
  
  <p>SQL:</p>
  
  <pre><code>with temp as 
  (
  SELECT a.ref_period, b.status, a.updated_dtm
   FROM ir_net_cndn_detail a,ir_net_cndn b
        WHERE a.bill_no=b.bill_no
        AND b.company_code = a.company_code     
        AND TO_DATE(a.ref_period,'MM/yyyy') &gt;= TO_DATE(&amp;p_ref_period_start,'MM/yyyy') 
        AND TO_DATE(a.ref_period,'MM/yyyy') &lt;= TO_DATE(&amp;p_ref_period_end,'MM/yyyy')      
  )  
  
     select a.ref_period, a.status, max(updated_dtm) as updated_dtm
     from temp a
     where TO_DATE(a.ref_period,'MM/yyyy') &gt;= TO_DATE(&amp;p_ref_period_start,'MM/yyyy') 
     AND TO_DATE(a.ref_period,'MM/yyyy') &lt;= TO_DATE(&amp;p_ref_period_end,'MM/yyyy')
     group by a.ref_period, a.status
  </code></pre>
  
  <p>Resut SQL:</p>
  
  <pre><code>ref_period |    status  | update_dtm
  01/2015  |  I   | 01/09/2016 13:29:56
  01/2015  |  I   | 18/05/2017 17:01:52
  01/2015  |  I   | 18/05/2017 16:16:23
  07/2015  |  I   | 01/09/2016 13:29:56
  07/2015  |  I   | 07/01/2016 10:17:39
  08/2015  |  I   | 01/09/2016 13:29:56
  09/2015  |  N   | 05/06/2017 15:59:55
  09/2015  |  I   | 01/09/2016 13:29:56
  10/2015  |  I   | 01/09/2016 13:29:56
  </code></pre>
  
  <p><strong>But I want Result:</strong></p>
  
  <pre><code>ref_period |    status  | update_dtm  &gt;&gt; I want max(update)/1 record with no duplication
  01/2015  |  I   | 18/05/2017 17:01:52
  07/2015  |  I   | 01/09/2016 13:29:56
  08/2015  |  I   | 01/09/2016 13:29:56
  09/2015  |  N   | 05/06/2017 15:59:55
  10/2015  |  I   | 01/09/2016 13:29:56
  </code></pre>