title: Get value based on max of a different column grouped by another column
body: <p>I want to get the values of a column based on max of a different column grouped by another column.</p>
  
  <p>I have this table:</p>
  
  <pre><code>KEY NUM VAL
  A   1   AB
  B   1   CD
  B   2   EF
  C   2   GH
  C   3   HI
  D   1   JK
  D   3   LM
  </code></pre>
  
  <p>And want this result:</p>
  
  <pre><code>KEY VAL
  A   AB
  B   EF
  C   HI
  D   LM
  </code></pre>
  
  <p>I could actually use this query to get it.</p>
  
  <pre><code>select KEY, VAL
  from TABLE_NAME TN
  where NUM = (
      select max(NUM)
      from TABLE_NAME TMP
      where TMP.KEY = TN.KEY
      )
  </code></pre>
  
  <p>However is there a more elegant way in ORACLE SQL (10g or above) to get the result?</p>
  
  <p>Reason behind it is that there are actually multiple <code>KEY</code>s and it just looks a bit ugly.</p>