title: Oracle - Select the latest distinct record from table
body: <p>In theory this seems easy but I just can't get my head around this...</p>
  
  <p>Here's my table info and data</p>
  
  <pre><code>ID    Heading    Date         Row_Num
   1       Test    12-MAR-12          1
   1      Test2    13-MAR-12          2
   2      Test3    13-MAR-12          3
  </code></pre>
  
  <p>And here's my query</p>
  
  <pre><code>select * from 
  table1 
  where date &lt;= :date 
  order by date desc
  </code></pre>
  
  <p><code>:date</code> being <code>14-MAR-12</code> for instance</p>
  
  <p>This obviously produces all three results but what I want to achieve from this query is the following data</p>
  
  <pre><code>ID    Heading    Date         Row_Num
   1      Test2    13-MAR-12          2
   2      Test3    13-MAR-12          3
  </code></pre>
  
  <p>So I added in a <code>distinct</code> but this doesn't work as expected as I have to group by each column and by doing that it produces 3 results still.</p>
  
  <p>Any ideas on how I can accomplish the result i'm after?</p>