Received: from sss.pgh.pa.us ([192.204.191.242]) by postgresql.org (8.11.3/8.11.4) with ESMTP id f78HR1630593 for ; Wed, 8 Aug 2001 13:27:01 -0400 (EDT) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id f78HQlY02094; Wed, 8 Aug 2001 13:26:47 -0400 (EDT) To: "Alex Page" cc: pgsql-sql@postgresql.org Subject: Re: Problem with aggregate functions and GROUP BY In-reply-to: <02ac01c12025$78644300$7fc472c1@solidstatelogic.com> References: <02ac01c12025$78644300$7fc472c1@solidstatelogic.com> Comments: In-reply-to "Alex Page" message dated "Wed, 08 Aug 2001 17:16:24 +0100" Date: Wed, 08 Aug 2001 13:26:47 -0400 Message-ID: <2091.997291607@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200108/132 X-Sequence-Number: 4353 "Alex Page" writes: > I'm trying to write a query that returns the rows containing the > most recent values for each foreign key. The best way to do this (on every dimension except portability :-() is SELECT DISTINCT ON. See the weather-report example in the SELECT reference page. regards, tom lane