Re: Selecting latest value - Mailing list pgsql-sql

From Stephan Szabo
Subject Re: Selecting latest value
Date
Msg-id Pine.BSF.4.21.0109200746550.74020-100000@megazone23.bigpanda.com
Whole thread Raw
In response to Re: Selecting latest value  (Patrik Kudo <kudo@partitur.se>)
List pgsql-sql
On Thu, 20 Sep 2001, Patrik Kudo wrote:

> On Thu, 20 Sep 2001, Haller Christoph wrote:
> 
> > Try
> > create NEWtable (userid text, val integer, ts timestamp);
> > insert into NEWtable
> > select userid, val, max(ts) from table group by userid, val;
> 
> That won't work. That will give me multiple userid-val combinations. Sure,
> the userid-val combinations will be unique, but I want unique userids
> with only the latest val for each userid.

Maybe something like: (assuming that ts is unique within each userid,
otherwise what does latest mean?  I haven't tried this, so it probably
doesn't parse, but...)

select userid, val from table where ts=(select max(ts) from table t wheret.userid=table.userid group by userid);



pgsql-sql by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: table restruct...
Next
From: Patrik Kudo
Date:
Subject: Re: Selecting latest value