Last active
June 14, 2019 19:01
-
-
Save skarger/5c8508cf2ebaba915cea573be6af85ef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT workouts.* | |
FROM workouts JOIN ( | |
SELECT max(id) AS id FROM ( | |
SELECT w.id, w.sport_id | |
FROM workouts w JOIN ( | |
SELECT sport_id, max(created_at) AS created_at | |
FROM workouts | |
GROUP BY sport_id | |
) latest_by_sport | |
ON w.created_at = w.created_at | |
AND w.sport_id = latest_by_sport.sport_id | |
) all_most_recent_by_sport | |
GROUP BY sport_id | |
) one_most_recent_by_sport | |
ON one_most_recent_by_sport.id = workouts.id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment