Received: from resy5.fzk.de (resy5.fzk.de [141.52.68.8]) by postgresql.org (8.11.3/8.11.4) with ESMTP id f8K9Bde63100 for ; Thu, 20 Sep 2001 05:11:40 -0400 (EDT) (envelope-from ch@rodos.fzk.de) Received: by rodos.fzk.de with ESMTP (8.8.6 (PHNE_17135)/8.7.1) id LAA25721; Thu, 20 Sep 2001 11:12:07 +0200 (METDST) From: Haller Christoph Message-Id: <200109200911.LAA25095@rodos> Subject: Re: Selecting latest value To: kudo@partitur.se (Patrik Kudo) Date: Thu, 20 Sep 2001 11:11:14 METDST Cc: pgsql-sql@postgresql.org In-Reply-To: ; from "Patrik Kudo" at Sep 19, 101 3:14 am X-Mailer: Elm [revision: 212.4] X-Archive-Number: 200109/167 X-Sequence-Number: 4847 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 >