I have what should be a simple question, but I can't figure out how to do it in DBIx::Class (which I'm using elsewhere in this code, so I need it for this too).
I have a single table, that (for this purpose) contains an ID, a name, and a score (and other data not relevant for this question). I want to get the Result object for the highest score for each name. That's it. So, for the data
I want to get back rows 2 (John's highest score), 5 (Kate's highest (and only) score), and 6 (Mary's highest score).+----+-----------+-------+ | id | name | score | +----+-----------+-------+ | 1 | John | 24 | | 2 | John | 60 | | 3 | Mary | 4 | | 4 | John | 10 | | 5 | Kate | 30 | | 6 | Mary | 20 | +---+------------+-------+
That is, the SQL would be something simple like SELECT MAX(score), name FROM scores GROUP BY name; (except that I want to get the Result object, not the actual column values).
How can I accomplish this? The docs are pretty sketchy about grouping in general, and I can't find a good parallel anywhere.
In reply to MAX and GROUP BY in DBIx::Class by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |