Wednesday, 28 August 2013

SELECT MAX() and corresponding field in the same row

SELECT MAX() and corresponding field in the same row

Here's my table A
orderID groupID nameID
1 grade A foo
2 grade A bar
3 grade A rain
1 grade B rain
2 grade B foo
3 grade B bar
1 grade C rain
2 grade C bar
3 grade C foo
Desired result:
rain
bar
foo
I need nameID of max(orderID) from each grade. I can get right orderID
from each grade, but nameID always stays as the first.
Thanks a Lot!

No comments:

Post a Comment