Re: picking max from list

From: Guy Fraser <guy(at)incentre(dot)net>
To: Jodi Kanter <jkanter(at)virginia(dot)edu>
Cc: Postgres SQL List <pgsql-sql(at)postgresql(dot)org>
Subject: Re: picking max from list
Date: 2003-12-10 23:11:10
Message-ID: 3FD7A80E.4000208@incentre.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

select group,rd_pk
from (select ...) as your_query,
(select max(run) as max_run,rd_pk as rd
from (select ...) as your_query) as max_rd
where rd = rd_pk
and max_run = run;

I dont know if you call that one query but it should work.

There may be more elegant solutions, but I havn't had a chance to read
up on the new join types.

Good luck

Jodi Kanter wrote:

> I have a query that produces results similar to this:
>
> run# rd_pk group#
> 0 9209 5
> 1 9209 8
> 0 9520 2
> 1 9520 5
> 0 9520 etc....
> 0 8652
> 1 8652
> 2 8652
> 0 8895
> 1 8894
>
> Ultimately I want to know the group number for EACH rd_pk with the
> highest run number. Can this be done in one query? Or will I need to
> code with a loop?
> Thanks
> Jodi

--
Guy Fraser
Network Administrator

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Michael A Nachbaur 2003-12-11 18:34:14 Using chkpass() in a query
Previous Message Bruno Wolff III 2003-12-10 20:53:40 Re: picking max from list