Re: SQL Question - Mailing list pgsql-general

From
Subject Re: SQL Question
Date
Msg-id [email protected]
Whole thread Raw
In response to SQL Question  (Alex <[email protected]>)
Responses Re: SQL Question
List pgsql-general
select max(lastupdate),prodid
from tablename
group by prodid


-----Original Message-----

From:  Thomas Kellerer <[email protected]>
Subj:  Re: [GENERAL] SQL Question
Date:  Fri Apr 15, 2005 7:24 am
Size:  621 bytes
To:  [email protected]

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


---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend




Joseph M Day
Global Innovative Solutions
651 W Washington Blvd
Chicago, IL 60661
D: (312) 371-3054
F: (312) 421-8557

pgsql-general by date:

Previous
From: Sean Davis
Date:
Subject: Re: PostgreSQL and Schema (pictures)
Next
From: "Joshua D. Drake"
Date:
Subject: Re: PostgreSQL and Schema (pictures)