pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chris Ruprecht <chrup999@yahoo.com>
To: pgsql-sql@postgresql.org
Subject: Re: Selecting latest value II
Date: Thu, 20 Sep 2001 10:25:58 -0500
Message-ID: <009501c141e8$8cb56200$5dd26383@corp.compucom.com> (raw)
References: <200109201402.QAA25852@rodos>

what about using 'distinct' in you select statement?

----- Original Message -----
From: "Haller Christoph" <ch@rodos.fzk.de>
To: "Patrik Kudo" <kudo@partitur.se>
Cc: <pgsql-sql@postgresql.org>
Sent: Thursday, September 20, 2001 11:02 AM
Subject: Re: [SQL] Selecting latest value II


> What do you mean by
> "the latest val for each userid"
> I cannot understand how a value of type integer
> can have a attribute like "latest".
> Sorry, but I need at least a bit more information.
> Regards, Christoph
> >
> > 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.
> >
> > /Patrik Kudo
> >
> > > >
> > > > 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
> > > >
> > >
> >
> >
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com




view thread (5+ messages)  latest in thread

Message-ID: <009501c141e8$8cb56200$5dd26383@corp.compucom.com>
Permalink:  ../009501c141e8$8cb56200$5dd26383@corp.compucom.com/
Also on:    postgresql.org/message-id/009501c141e8$8cb56200$5dd26383@corp.compucom.com

 · 

reply

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: chrup999@yahoo.com
  Subject: Re: Selecting latest value II
  In-Reply-To: <009501c141e8$8cb56200$5dd26383@corp.compucom.com>

* 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