Consider a table like this:
| Name | Version | Other |
| ---------------------|-------|
| Foo | 1 | 'a' |
| Foo | 2 | 'b' |
| Bar | 5 | 'c' |
| Baz | 3 | 'd' |
| Baz | 4 | 'e' |
| Baz | 5 | 'f' |
--------------------------------
I would like to write a sqlalchemy query statement to list all items (as mapper objects, not just the Name column) with max version: Foo-2-b, Bar-5-c, Baz-5-f
. I understand that I would have to use the group_by
method, but beyond that I am puzzled as to how to retrieve the sub-lists (and then find the max element). SQLAlchemy documentation is apparently not very clear on this.
In the real scenario, there are many other columns (like 'Other') - which is why I need the actual row object (mapper class) to be returned rather than just the 'Name' value.