SELECT DISTINCT ON (r.id) t.id, t.headline, t.posted_at, r.id r.posted_at, FROM threads AS t JOIN replies AS r ON r.thread_id = t.id ORDER BY r.posted_at LIMIT 100