Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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