LMSouq
database Open

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

YA
Yarin
1 month ago
3 views
Problem Description
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: |Person | Group | Age| |-------|-------|----| |Shawn | 1 | 42 | |Laura | 2 | 39 |

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base