Hi, Thurstan
On Thu, 20 Sep 2001 17:30:46 +0100, "Thurstan R. McDougle"
<[EMAIL PROTECTED]> wrote:
> [...]
>Carl van Tast had 2 good methods as follows
>
>SELECT userid, val
>FROM tbl
>WHERE NOT EXISTS (SELECT * FROM tbl AS t2
> WHERE tbl.userid=t2.userid AND t2.ts > tbl.ts);
>
Hi back
Carl van Tast wrote:
>
> Hi, Thurstan
>
> On Thu, 20 Sep 2001 17:30:46 +0100, "Thurstan R. McDougle"
> <[EMAIL PROTECTED]> wrote:
>
> > [...]
> >Carl van Tast had 2 good methods as follows
> >
> >SELECT userid, val
> >FROM tbl
> >WHERE NOT EXISTS (SELECT * FROM tbl AS t2
> >
Look at his table structure, you will see a timestamp. His request can
be rephrased as "The val field from the latest record for each userid in
turn.
Carl van Tast had 2 good methods as follows
SELECT userid, val
FROM tbl
WHERE NOT EXISTS (SELECT * FROM tbl AS t2
WHERE tbl.us
what about using 'distinct' in you select statement?
- Original Message -
From: "Haller Christoph" <[EMAIL PROTECTED]>
To: "Patrik Kudo" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Thursday, September 20, 2001 11:02 AM
Subject: Re:
Patrik Kudo <[EMAIL PROTECTED]> writes:
> 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
On Thu, 20 Sep 2001, Tom Lane wrote:
> This is what SELECT DISTINCT ON was invented for. I don't know any
> comparably easy way to do it in standard SQL, but with DISTINCT ON
> it's not hard:
>
> SELECT DISTINCT ON (userid) userid, val, ts FROM table
> ORDER BY userid, ts DESC;
>
> See the DIST
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 multipl
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 (use
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 combinati
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);
>
> Thi
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, exc
11 matches
Mail list logo