title: Select Rows with Maximum Column Value group by Another Column
body: <p>This should be a simple question, but I can't get it to work :(</p>
  
  <p>How to select rows that have the maximum column value,as group by another column?</p>
  
  <p>For example, </p>
  
  <p>I have the following table definition:</p>
  
  <pre><code>ID
  Del_Index
  docgroupviewid
  </code></pre>
  
  <p>The issue now is that I want to group by results by <code>docgroupviewid</code> first, and then choose one row from each <code>docgroupviewid</code> group, depending on which one has the highest <code>del_index</code>.</p>
  
  <p>I tried </p>
  
  <pre><code>SELECT docgroupviewid, max(del_index),id FROM table
  group by docgroupviewid
  </code></pre>
  
  <p>But instead of return me with the correct <code>id</code>, it returns me with the earliest <code>id</code> from the group with the same <code>docgroupviewid</code>. </p>
  
  <p>Any ideas?</p>