From: Haller Christoph <ch@rodos.fzk.de>
To: kudo@partitur.se
Cc: pgsql-sql@postgresql.org
Subject: Re: Selecting latest value
Date: Thu, 20 Sep 2001 11:11:14 METDST
Message-ID: <200109200911.LAA25095@rodos> (raw)
In-Reply-To: <Pine.BSF.4.31.0109181816420.74890-100000@tb303.partitur.se>
Try
create NEWtable (userid text, val integer, ts timestamp);
insert into NEWtable
select userid, val, max(ts) from table group by userid, val;
Regards, Christoph
>
> Hi,
>
> I have a table which basically looks like this:
>
> create table (userid text, val integer, ts timestamp);
>
> This table holds multiple values for users, timestamped for history
> reasons.
>
> Now I need to fetch the latest val for each userid to insert into a new
> table (with about the same schema, except for uniqueness on userid).
> I belive this should be a trivial task, but I'm experience total lack of
> insight here...
>
> Comments?
>
> /Patrik Kudo
>
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: ch@rodos.fzk.de, kudo@partitur.se
Subject: Re: Selecting latest value
In-Reply-To: <200109200911.LAA25095@rodos>
* 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