postgresql: limit 1 on group by

It's stupidly complicated to get just one record per group on a PostgreSQL query...

After an hour of trial and error this worked for me:

SELECT DISTINCT ON (c_order_id) c_order_id
FROM c_invoice


No Group By or Limit 1 functions needed.



Leave a Reply

Your email address will not be published. Required fields are marked *