Re: Getting pk of the most recent row, in a group by

From: Rodrigo De León <rdeleonp(at)gmail(dot)com>
To: "Bryce Nesbitt" <bryce1(at)obviously(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Getting pk of the most recent row, in a group by
Date: 2007-08-13 20:16:49
Message-ID: a55915760708131316t4ae9e506i3980e4ad87a8268c@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 8/13/07, Bryce Nesbitt <bryce1(at)obviously(dot)com> wrote:
> In the second example, is it possible to get the primary key of the row
> with the minimum expires time?

SELECT TYPE, MIN(expires), COUNT(*)
, (SELECT MIN(coupon_id)
FROM coupon
WHERE expires = MIN(c.expires)) AS coupon_id
FROM coupon c
GROUP BY TYPE;

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Glaesemann 2007-08-13 20:19:05 Re: Getting pk of the most recent row, in a group by
Previous Message Bryce Nesbitt 2007-08-13 20:05:40 Getting pk of the most recent row, in a group by