Skip to content

Instantly share code, notes, and snippets.

@lettergram
Last active May 14, 2019 04:00
Show Gist options
  • Save lettergram/d7031fd45e458b5066aadc9ba3669ba1 to your computer and use it in GitHub Desktop.
Save lettergram/d7031fd45e458b5066aadc9ba3669ba1 to your computer and use it in GitHub Desktop.
Create a subquery in PostgreSQL
/**
* comments
* author
* comment_text
* created_at
**/
SELECT author, created_at FROM
(SELECT * FROM comments WHERE (created_at >= NOW() - interval '6 month')
ORDER BY created_at DESC LIMIT 100) subquery
ORDER BY author ASC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment