See if this works; the max aggregate in the subquery could be just about any function, since it's only going to join to one row.
select max(m1.output_date), m1.parent_id, max(m2.output_id) as latest_output from my_table M1 inner join (select output_date, output_id, parent_ID from my_table) as M2 on m1.output_date = m2.output_date and m1.parent_ID = m2.parent_ID Where M1.output_date < now() Group by m1.parent_id
-- Mark
Ashish Karalkar <ashish_postgre@yahoo.co.in> Sent by: pgsql-novice-owner@postgresql.org