Created
December 12, 2014 03:47
-
-
Save slattery/08d1d70dbe87fb88e93e to your computer and use it in GitHub Desktop.
get first in each category in PostgreSQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT DISTINCT ON (message_id) message_id, date_trunc('day', load_time) as load_time | |
| FROM www_acp.outgoing_messages | |
| WHERE message_id IN (select document_id from documents where name ilike '%whatevz%') | |
| ORDER BY message_id, load_time | |
| -- this acts sort of like a group by with min( timestamp ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment