pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
To: Devrim GUNDUZ <devrim@oper.metu.edu.tr>
To: pgsql-sql@postgresql.org
Subject: Re: Select + min question
Date: Sun, 23 Jun 2002 20:16:16 +0800
Message-ID: <002001c21aaf$c73cba40$0200a8c0@SOL> (raw)
References: <Pine.LNX.4.44.0206231435370.11727-100000@oper.metu.edu.tr>

> 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





view thread (4+ messages)  latest in thread

Message-ID: <002001c21aaf$c73cba40$0200a8c0@SOL>
Permalink:  ../002001c21aaf$c73cba40$0200a8c0@SOL/
Also on:    postgresql.org/message-id/002001c21aaf$c73cba40$0200a8c0@SOL

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: chriskl@familyhealth.com.au, devrim@oper.metu.edu.tr
  Subject: Re: Select + min question
  In-Reply-To: <002001c21aaf$c73cba40$0200a8c0@SOL>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox