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