Postgres SELECT DISTINCT, only highest values [duplicate]
Use order by
to get the max index_id
SELECT DISTINCT ON (level) index_id FROM indexes order by level, index_id desc
Try tou use GROUP BY instead of DISTINCT ON
SELECT MAX(index_id) FROM indexes GROUP BY level