Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 431E64759F9 for ; Sun, 23 Jun 2002 08:23:14 -0400 (EDT) Received: from t-online.fr (mail2.in.t-online.fr [213.44.120.47]) by postgresql.org (Postfix) with ESMTP id B8B7D475C6C for ; Sun, 23 Jun 2002 08:22:14 -0400 (EDT) Received: from t-online.fr (localhost [127.0.0.1]) by localhost.in.t-online.fr (Postfix) with ESMTP id C5C4448F3; Sun, 23 Jun 2002 14:22:16 +0200 (CEST) Received: from denis-bsd.in.t-online.fr (denis-bsd.in.t-online.fr [213.44.126.6]) by t-online.fr (Postfix) with ESMTP id 10E6348F2; Sun, 23 Jun 2002 14:22:16 +0200 (CEST) Date: Sun, 23 Jun 2002 14:22:17 +0200 From: Mathieu Arnold To: Devrim GUNDUZ , pgsql-sql@postgresql.org Subject: Re: Select + min question Message-ID: <42040000.1024834936@denis-bsd.in.t-online.fr> In-Reply-To: References: X-Mailer: Mulberry/2.2.1 (Linux/x86) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Archive-Number: 200206/315 X-Sequence-Number: 8280 --On Sunday, June 23, 2002 14:36:14 +0300 Devrim GUNDUZ wrote: > > Hi, > > I have created a table like this: > > CREATE TABLE test ( > b_date char(8), > active boolean, > id serial > ); > > and inserted some rows. > > Now, what I want is to select the b_date which has the minimum "id" and > active=t. > > A normal query would be : > SELECT b_date,min(id) FROM test WHERE active='t' GROUP BY id LIMIT 1 > > However, I only want to select b_date. So, if I perform the following > query, I get the following error: > > devrim=# SELECT b_date FROM test WHERE active='t' AND id=min(id) LIMIT 1; > ERROR: Aggregates not allowed in WHERE clause > > What should I do? ANy suggestions? I believe that : SELECT b_date, id FROM test WHERE active='t' ORDER BY id LIMIT 1; is the right thing. -- Mathieu Arnold