Re: Select + min question

From: "Christopher Kings-Lynne" <chriskl(at)familyhealth(dot)com(dot)au>
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:16:16
Message-ID: 002001c21aaf$c73cba40$0200a8c0@SOL
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> 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

Use a subselect (and don't compare to 't' if it's a boolean field...)

SELECT b_date FROM test WHERE active AND id=(SELECT min(id) FROM test) LIMIT
1;

Chris

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Mathieu Arnold 2002-06-23 12:22:17 Re: Select + min question
Previous Message Devrim GUNDUZ 2002-06-23 11:36:14 Select + min question