Re: Problem using Subselect results

From: "Oliver Heinz" <oheinz(at)stud(dot)fbi(dot)fh-darmstadt(dot)de>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Problem using Subselect results
Date: 2003-07-29 15:14:12
Message-ID: 000401c355e4$11b0cdd0$0f02a8c0@spineofgod
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I'll try this tomorrow - combining DISTINCT ON (two.two_id) and sorting by
two.updatenr could (should) have the desired effect - I never thought about
using ORDER and DISTINCT that way.

I'll report my success or failure...

Thanks so far!

Bye,
Oliver

----- Original Message -----
From: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: <oheinz(at)stud(dot)fbi(dot)fh-darmstadt(dot)de>
Cc: <pgsql-sql(at)postgresql(dot)org>
Sent: Tuesday, July 29, 2003 5:00 PM
Subject: Re: [SQL] Problem using Subselect results

> oheinz(at)stud(dot)fbi(dot)fh-darmstadt(dot)de writes:
> > But as this data is time sensitive, we introduce some kind of time
stamp - a
> > serial which is global to all tables. Now, for each record in table
'one' i
> > want to see only the corresponding records in tables two, three, etc...
that
> > were created before 'one.updatenr'
>
> > SELECT * FROM one, two WHERE (one.two_id=two.two_id AND one.updatenr >
> > two.updatenr);
>
> > This might match multiple records in tables two (two_id is not a pk, we
have
> > historic records in this table). Now I want only the most current
version
> > before one.updatenr. - And that's where I run into trouble.
>
> You might be able to make this work by using SELECT DISTINCT ON. See
> the "weather reports" example in the SELECT reference page.
>
> regards, tom lane
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Antony Gubert 2003-07-29 15:14:19 Unsubscribe
Previous Message Tom Lane 2003-07-29 15:00:56 Re: Problem using Subselect results