Re: Select + min question

From: Mathieu Arnold <mat(at)mat(dot)cc>
To: Devrim GUNDUZ <devrim(at)oper(dot)metu(dot)edu(dot)tr>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Select + min question
Date: 2002-06-23 12:22:17
Message-ID: 42040000.1024834936@denis-bsd.in.t-online.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

--On Sunday, June 23, 2002 14:36:14 +0300 Devrim GUNDUZ
<devrim(at)oper(dot)metu(dot)edu(dot)tr> 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Devrim GUNDUZ 2002-06-24 06:18:00 Re: Select + min question
Previous Message Christopher Kings-Lynne 2002-06-23 12:16:16 Re: Select + min question