Skip to content

Instantly share code, notes, and snippets.

@p5k6
Created January 9, 2015 17:30
Show Gist options
  • Save p5k6/c15cbb396854fe1af308 to your computer and use it in GitHub Desktop.
Save p5k6/c15cbb396854fe1af308 to your computer and use it in GitHub Desktop.
I think this would work?
select * from (
SELECT shows.* , ROW_NUMBER() OVER(PARTITION BY e.show_id ORDER BY e.airs_on) AS r
FROM episodes e
join shows s on s.id=e.show_id
WHERE e.airs_on >= NOW()
) a
where r=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment