Re: Need help with what I think is likely a simple query - for each distinct val, return only the record with the most recent date.

From: Toby Corkindale <toby(dot)corkindale(at)strategicdata(dot)com(dot)au>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Need help with what I think is likely a simple query - for each distinct val, return only the record with the most recent date.
Date: 2011-09-13 06:43:47
Message-ID: 4E6EFBA3.7030104@strategicdata.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 13/09/11 10:54, Reid Thompson wrote:
> Could someone point me in the right direction..
> Thanks - reid
>
> Given the example data,
> how do I write a query that will give me the resultset:
[snip]
> I.E. for each distinct val, return the record with the most recent date.

Isn't it something simple like this?

SELECT val, max(date) GROUP BY val;

-Toby

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Kellerer 2011-09-13 06:44:54 Re: Problem with the 9.1 one-click installer Windows7 64bit
Previous Message Devrim GÜNDÜZ 2011-09-13 05:43:38 Re: 9.0, 9.1 RPM based parallel execution?