Re: SQL Question

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL Question
Date: 2005-04-15 12:15:00
Message-ID: d3ob1h$1s0$1@sea.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message GIROIRE, Nicolas (COFRAMI) 2005-04-15 12:23:26 Re: SQL Question
Previous Message Alejandro D. Burne 2005-04-15 12:13:40 If statements on select