Re: SQL Question - Mailing list pgsql-general

From Thomas Kellerer
Subject Re: SQL Question
Date
Msg-id d3ob1h$1s0$1@sea.gmane.org
Whole thread Raw
In response to SQL Question  (Alex <alex@meerkatsoft.com>)
List pgsql-general
On 15.04.2005 13:58 Alex wrote:

> Hi,
>
> i have a table
>
> ProdId | LastUpdate
> -------+------------
> 100    | 2005-04-01
> 100    | 2005-03-01
> 100    | 2005-02-01
> 200    | 2005-04-01
> 200    | 2005-03-01
> 200    | 2005-02-01
>
> - How can i select only the newest record for each ProdId ?
>
> 100    | 2005-04-01
> 200    | 2005-04-01
>
SELECT prodid,
       lastupdate
FROM produpdate p1
WHERE lastupdate = (SELECT MAX (lastupdate) FROM produpdate p2 WHERE p2.prodid =
p1.prodid)

Thomas

pgsql-general by date:

Previous
From: "Alejandro D. Burne"
Date:
Subject: If statements on select
Next
From: "GIROIRE, Nicolas (COFRAMI)"
Date:
Subject: Re: SQL Question