Re: ids from grouped rows

From: Ragnar Hafstað <gnari(at)simnet(dot)is>
To: Lindsay <hellolindsay(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: ids from grouped rows
Date: 2005-07-20 14:50:12
Message-ID: 1121871013.17734.9.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, 2005-07-20 at 08:46 -0400, Lindsay wrote:

> SELECT name, MAX(age), id_for_row_with_max_age
> FROM Person
> GROUP BY name

how about:
select distinct on (name) name, age, id
from person
order by name, age desc;

gnari

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Erik Wasser 2005-07-20 15:48:38 Re: [despammed] Re: 'show full processlist' in postgres?
Previous Message Weinzierl Stefan 2005-07-20 14:09:23 Re: ids from grouped rows