PG rejects `SELECT DISTINCT c.id, c.manga_id, cs.source_url ... ORDER BY c.manga_id, c.created_at` because the ORDER BY references a column not in the DISTINCT projection. Wrap the DISTINCT in a subquery (which includes created_at) and apply the ORDER BY in the outer SELECT. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>