Skip to content

Instantly share code, notes, and snippets.

@skarger
Created June 12, 2019 18:52
Show Gist options
  • Select an option

  • Save skarger/194629dce810b881a89efc9eedbd1ce2 to your computer and use it in GitHub Desktop.

Select an option

Save skarger/194629dce810b881a89efc9eedbd1ce2 to your computer and use it in GitHub Desktop.
SELECT workouts.*
FROM workouts JOIN (
SELECT sport_id, max(created_at) AS created_at
FROM workouts
GROUP BY sport_id
) latest_by_sport
ON workouts.created_at = latest_by_sport.created_at
AND workouts.sport_id = latest_by_sport.sport_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment