I\'m trying to create a Flask app that shows the latest score from individual players. So a player can have multiple scores, but on the leaderboard I only want to show her m
You can use the DISTINCT ON ... ORDER BY "idiom" in Postgresql to get the greatest-n-per-group, where n equals 1, given that your table isn't huge:
players_with_score = db.session.query(Player, Score).\
join(Score).\
distinct(Player.id).\
order_by(Player.id, Score.timestamp.desc())
Since Score.timestamp
is not nullable, you do not need to worry about descending order and NULLs.