Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 0619E475C77 for ; Fri, 30 Aug 2002 14:48:52 -0400 (EDT) Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (Postfix) with ESMTP id 4FF4E4759BD for ; Fri, 30 Aug 2002 14:48:51 -0400 (EDT) Received: from [66.219.92.2] (HELO chocolate-mousse) by davinci.ethosmedia.com (CommuniGate Pro SMTP 3.5.9) with ESMTP id 1629308; Fri, 30 Aug 2002 11:48:50 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: Marco Muratori , Subject: Re: query problem Date: Thu, 29 Aug 2002 13:45:25 -0700 X-Mailer: KMail [version 1.4] References: In-Reply-To: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200208291345.25680.josh@agliodbs.com> X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/428 X-Sequence-Number: 9274 Marco, > Is there a way to obtain this records by performing one > single query and not by making for each city something like > "SELECT city,date FROM table WHERE city=3D'London' AND date>'2002-07-19 > 15:39:15+00' ORDER BY date ASC LIMIT 1;"? Close. Try: SELECT city, MAX("date") as last_date FROM table WHERE "date" > $date GROUP BY city ORDER BY city Though as an aggregate query, this will be slow on large tables. --=20 -Josh Berkus Aglio Database Solutions San Francisco