pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Achilleus Mantzios <achill@matrix.gatewaynet.com>
To: Joachim Trinkwitz <jtr@uni-bonn.de>
Cc: pgsql-sql@postgresql.org
Subject: Re: Aggregates not allowed in WHERE clause?
Date: Wed, 19 Jun 2002 11:18:13 +0300 (EEST)
Message-ID: <Pine.LNX.4.44.0206191115510.7173-100000@matrix.gatewaynet.com> (raw)
In-Reply-To: <874rfzr8xj.fsf@waffel.germanistik.uni-bonn.de>

On 19 Jun 2002, Joachim Trinkwitz wrote:

> Hi all,
> 
> I have a table (lv) with a field "semester" and I'm trying to fish out all
> rows which have a value corresponding to a max() value of another
> table's (lf_sem) "semester" field. The intention is to keep a value
> with the current term in lf_sem so I can get all rows which concern
> this term.
> 
> Example tables:
> 
> lv
> ==
> semester | kvvnr
> ---------+------
> 2001ss   | 4185
> 2001ss   | 4203
> 2002ws   | 4163
> 2002ws   | 4190
> 
> lf_sem
> ======
> semester
> --------
> 2001ws
> 2002ss
> 2002ws
> 
> At first I tried this query:
> 
>   SELECT kvvnr
>   FROM lv, lf_sem
>   WHERE lv.semester = max(lf_sem.semester);
> 
> This yields the message: 'Aggregates not allowed in WHERE clause'.
> 
> Next I tried this one:
> 
>   SELECT kvvnr, max(lf_sem.semester) AS akt_semester
>   FROM lv, lf_sem
>   WHERE lv.semester = akt_semester;
> 
> Now I got: 'Attribute 'akt_semester' not found'
> 
> Is there another way to get what I want?

SELECT lv.kvvnr,lv.semester from lv where lv.semester = (select 
max(semester) from lf_sem); 

> 
> Clueless,
> joachim
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
> 

-- 
Achilleus Mantzios
S/W Engineer
IT dept
Dynacom Tankers Mngmt
tel:    +30-10-8981112
fax:    +30-10-8981877
email:  achill@matrix.gatewaynet.com
        mantzios@softlab.ece.ntua.gr




view thread (5+ messages)  latest in thread

Message-ID: <Pine.LNX.4.44.0206191115510.7173-100000@matrix.gatewaynet.com>
Permalink:  ../Pine.LNX.4.44.0206191115510.7173-100000@matrix.gatewaynet.com/
Also on:    postgresql.org/message-id/Pine.LNX.4.44.0206191115510.7173-100000@matrix.gatewaynet.com

 · 

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: achill@matrix.gatewaynet.com, jtr@uni-bonn.de
  Subject: Re: Aggregates not allowed in WHERE clause?
  In-Reply-To: <Pine.LNX.4.44.0206191115510.7173-100000@matrix.gatewaynet.com>

* 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