X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id F1E0353505 for ; Wed, 13 Apr 2005 10:01:07 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 24753-01 for ; Wed, 13 Apr 2005 13:01:02 +0000 (GMT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id BE446534F9 for ; Wed, 13 Apr 2005 10:01:01 -0300 (ADT) Received: (qmail 5084 invoked by uid 500); 13 Apr 2005 13:20:19 -0000 Date: Wed, 13 Apr 2005 08:20:19 -0500 From: Bruno Wolff III To: "A. R. Van Hook" Cc: pgsql-sql@postgresql.org Subject: Re: max question Message-ID: <20050413132019.GB4594@wolff.to> Mail-Followup-To: Bruno Wolff III , "A. R. Van Hook" , pgsql-sql@postgresql.org References: <425C0445.8020603@lake-lotawana.mo.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <425C0445.8020603@lake-lotawana.mo.us> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.01 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200504/184 X-Sequence-Number: 21077 On Tue, Apr 12, 2005 at 12:24:21 -0500, "A. R. Van Hook" wrote: > I have the following in a table: > oid | citkey | contby | contdate | abcontinue | ccdate > ---------+------------+----------+------------+------------+------------ > 5774835 | 04-0594703 | | | | > 5775325 | 04-0594703 | Attorney | 04/06/2005 | 6 | 03/07/2005 > 5776060 | 04-0594703 | Attorney | 05/04/2005 | 6 | 04/05/2005 > 5776067 | 04-0594703 | Attorney | 05/04/2005 | 6 | 04/05/2005 > > I am trying to pull rows that have the max. contdate. Why does the > following give more than 2 rows? > ql "select oid,* from ccontinue where citkey ='04-0594703' group by > oid,citkey,contby,contdate,abcontinue,ccdate having max(contdate) = > contdate" If you group by oid you are going to get a separate group for each row. You haven't told us what you actually expect for output, so I don't have specific advise for a query. However, you might find the Postgres extension DISTINCT ON useful, depending on exactly what you want. > oid | citkey | contby | contdate | abcontinue | ccdate > ---------+------------+----------+------------+------------+------------ > 5776067 | 04-0594703 | Attorney | 05/04/2005 | 6 | 04/05/2005 > 5775325 | 04-0594703 | Attorney | 04/06/2005 | 6 | 03/07/2005 > 5776060 | 04-0594703 | Attorney | 05/04/2005 | 6 | 04/05/2005 > (3 rows) > > thanks > > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq