From a simple table with three rows (id, status, value), I would like to retrieve the id and the value from the row with the maximum value, for each status group.
The simple query I tried is:
SELECT t1.status, t1.id, MAX(t1.value) FROM t1
GROUP BY t1.status;
The problem is that I do get maximum value for each group, but not the correct id. I get the the id of the first row from each status group... Is there a simple way to get the proper id?
There are many questions about getting the maximum value, but aren't many about the id. Couldn't find an answer for that one..