Skip to content

Instantly share code, notes, and snippets.

@blueset
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blueset/41a5563d2b5b482a0139 to your computer and use it in GitHub Desktop.
Save blueset/41a5563d2b5b482a0139 to your computer and use it in GitHub Desktop.
Github Pastebin
SELECT title, content, category, pub_time
FROM news
WHERE (
SELECT count(*) FROM news AS f
WHERE f.category = news.category AND f.pub_time <= news.pub_time
) <= 2;
# Via http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment