SELECT event_id, subpool_id, no_tickets, automatic FROM "Global".tickets_event_subpool WHERE subpool_id = 6854 ORDER BY subpool_id, automatic, no_tickets DESC RETURNS: 1431,6854,-118,f 1020,6854,-123,f 1020,6854,-125,f 500,6854,11,t 1394,6854,8,t 1431,6854,3,t 1020,6854,2,t I want to get rid of double records (event_id's), so that larger numbers are preffered. I tried doing it like this, but it doesn't work: SELECT DISTINCT ON (a.event_id) a.event_id,a.subpool_id, a.no_tickets, a.automatic FROM ( SELECT event_id, subpool_id, no_tickets, automatic FROM "Global".tickets_event_subpool WHERE subpool_id = 6854 ORDER BY subpool_id, automatic, no_tickets DESC) as a LIMIT 10 500,6854,11,t 1020,6854,-123,f 1394,6854,8,t 1431,6854,-118,f 1020 should have no_tickets=2 instead of -123