Comment Comment by felixge Maybe I'm missing something, but the final query in the article seems complicated/inefficient for no apparent reason. IMO this one should be better: SELECT DISTINCT ON (message_id) message_id, status FROM emails ORDER BY message_id, created_at; parent felixge 9 years ago