X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 7F960D1E810 for ; Mon, 19 Jan 2004 05:45:43 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 25767-01 for ; Mon, 19 Jan 2004 01:45:12 -0400 (AST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 38360D1E83E for ; Mon, 19 Jan 2004 01:45:11 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.10/8.12.10) with ESMTP id i0J5iUpH020990; Mon, 19 Jan 2004 00:44:31 -0500 (EST) To: Robert Creager Cc: PGSQL Subject: Re: How can I get the last element out of GROUP BY sets? In-reply-to: <20040118212834.7c667b9b.Robert_Creager@LogicalChaos.org> References: <20040118212834.7c667b9b.Robert_Creager@LogicalChaos.org> Comments: In-reply-to Robert Creager message dated "Sun, 18 Jan 2004 21:28:34 -0700" Date: Mon, 19 Jan 2004 00:44:30 -0500 Message-ID: <20989.1074491070@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/163 X-Sequence-Number: 16556 Robert Creager writes: > ... one piece of data I need is the last value for each GROUP BY > period. Alas, I cannot figure out how to do this. SELECT DISTINCT ON (rather than GROUP BY) could get this done for you. regards, tom lane