From: jday@gisolutions.us
To: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-general@postgresql.org
Subject: Re: SQL Question
Date: Fri, 15 Apr 2005 9:42:00 -0500
Message-ID: <20050415144200.A1C1C5406F@svr1.postgresql.org> (raw)
select max(lastupdate),prodid
from tablename
group by prodid
-----Original Message-----
From: Thomas Kellerer <spam_eater@gmx.net>
Subj: Re: [GENERAL] SQL Question
Date: Fri Apr 15, 2005 7:24 am
Size: 621 bytes
To: pgsql-general@postgresql.org
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: jday@gisolutions.us, spam_eater@gmx.net
Subject: Re: SQL Question
In-Reply-To: <20050415144200.A1C1C5406F@svr1.postgresql.org>
References: <20050415144200.A1C1C5406F@svr1.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox