pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: oheinz@stud.fbi.fh-darmstadt.de
Cc: pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
Subject: Re: Problem using Subselect results
Date: Tue, 29 Jul 2003 11:00:56 -0400
Message-ID: <22142.1059490856@sss.pgh.pa.us> (raw)
In-Reply-To: <1059478450.3f265bb210e14@stud.fbi.fh-darmstadt.de>
References: <1058964708.3f1e84e407a8d@stud.fbi.fh-darmstadt.de>
	<200307280947.21658.josh@agliodbs.com>
	<1059478450.3f265bb210e14@stud.fbi.fh-darmstadt.de>

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



view thread (15+ messages)  latest in thread

Message-ID: <22142.1059490856@sss.pgh.pa.us>
Permalink:  ../22142.1059490856@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/22142.1059490856@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, oheinz@stud.fbi.fh-darmstadt.de
  Subject: Re: Problem using Subselect results
  In-Reply-To: <22142.1059490856@sss.pgh.pa.us>

* 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