Re: Select + min question - Mailing list pgsql-sql

From Christopher Kings-Lynne
Subject Re: Select + min question
Date
Msg-id 002001c21aaf$c73cba40$0200a8c0@SOL
Whole thread Raw
In response to Select + min question  (Devrim GUNDUZ <devrim@oper.metu.edu.tr>)
Responses Re: Select + min question
List 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




pgsql-sql by date:

Previous
From: Devrim GUNDUZ
Date:
Subject: Select + min question
Next
From: Mathieu Arnold
Date:
Subject: Re: Select + min question