title: Oracle SQL query: Retrieve latest values per group based on time
body: <p>I have the following table in an Oracle DB</p>
  
  <pre><code>id     date              quantity
  1      2010-01-04 11:00  152
  2      2010-01-04 11:00  210
  1      2010-01-04 10:45  132
  2      2010-01-04 10:45  318
  4      2010-01-04 10:45  122
  1      2010-01-04 10:30  1
  3      2010-01-04 10:30  214
  2      2010-01-04 10:30  5515
  4      2010-01-04 10:30  210
  </code></pre>
  
  <p>now I'd like to retrieve the latest value (and its time) per id. Example output:</p>
  
  <pre><code>id     date              quantity
  1      2010-01-04 11:00  152
  2      2010-01-04 11:00  210
  3      2010-01-04 10:30  214
  4      2010-01-04 10:45  122
  </code></pre>
  
  <p>I just can't figure out how to put that into a query...</p>
  
  <p>Additionally the following options would be nice:</p>
  
  <p>Option 1: the query should only return values that are from the last XX minutes.</p>
  
  <p>Option 2: the id should be concatenated with text from another table that has id and idname. output for id should then be like: id-idname (eg 1-testid1).</p>
  
  <p>many thanks for any help!</p>