Received: from eba-haus.de ([149.228.241.205]) by hub.org (8.10.1/8.10.1) with SMTP id e5G94TI34062 for ; Fri, 16 Jun 2000 05:04:30 -0400 (EDT) Received: from kopo001 by eba-haus.de;Fri, 16 Jun 2000 08:56:29 GMT with Novell_GroupWise; Fri, 16 Jun 2000 10:56:30 +0200 Message-Id: X-Mailer: Novell GroupWise 5.5.2 Date: Fri, 16 Jun 2000 10:56:04 +0200 From: "Gerhard Dieringer" To: Cc: "<" Subject: Re: Antw: using max() aggregate Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Disposition: inline Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by hub.org id e5G94WI34064 X-Archive-Number: 200006/164 Louis-David Mitterrand - ldm@apartia.org - http://www.apartia.fr wrote: > ... > Yes this would work nicely but if I need to add more conditional clauses > I have to duplicate them in the main SELECT and in the sub-SELECT: > > SELECT title,max(stopdate) > FROM auction > WHERE stopdate = (SELECT max(stopdate) FROM auction AND stopdate > now()) > AND stopdate > now(); > > Or am I missing something? > > Tom Lane suggested using: > > SELECT title,stopdate FROM auction ORDER BY stopdate LIMIT 1; > > which seems the best solution (I was a bit concerned about performance, > but then again the max() aggregate does a scan of all rows as well). > ... I don't see why you repeat your conditions in the outer select. The condition in the inner select drops all records that violate the conditions, so the same conditions in the outer select have nothing to do and you can leave them away. Tom's solution has the drawback, that if you have more than one record with the same max value you only get one of them, but may be that you want to see all of them. Gerhard