Re: Problem using Subselect results - Mailing list pgsql-sql

From Tom Lane
Subject Re: Problem using Subselect results
Date
Msg-id 22142.1059490856@sss.pgh.pa.us
Whole thread Raw
In response to Re: Problem using Subselect results  (oheinz@stud.fbi.fh-darmstadt.de)
List pgsql-sql
oheinz@stud.fbi.fh-darmstadt.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


pgsql-sql by date:

Previous
From: "Mark Roberts"
Date:
Subject: unsubscribe
Next
From: "Oliver Heinz"
Date:
Subject: Re: Problem using Subselect results