Get records with max value for each group of grouped SQL results

How do you get the rows that contain the max value for each grouped set?

I’ve seen some overly-complicated variations on this question, and none with a good answer. I’ve tried to put together the simplest possible example:

Given a table like that below, with person, group, and age columns, how would you get the oldest person in each group? (A tie within a group should give the first alphabetical result)

Person | Group | Age
---
Bob  | 1     | 32  
Jill | 1     | 34  
Shawn| 1     | 42  
Jake | 2     | 29  
Paul | 2     | 36  
Laura| 2     | 39  

Desired result set:

Shawn | 1     | 42    
Laura | 2     | 39  

19 Answers
19

Leave a Comment