postgresql: limit 1 on group by By Ricardo MallaFebruary 28, 2017postgresql 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.