Re: self-join on subselect

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: PFC <lists(at)boutiquenumerique(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: self-join on subselect
Date: 2005-01-27 05:45:41
Message-ID: 20050127054541.GB23835@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Jan 26, 2005 at 23:12:25 +0100,
PFC <lists(at)boutiquenumerique(dot)com> wrote:
>
> How do you do a self-join on a subselect ?
>
> like
> SELECT a.x+b.x FROM (subselect) a, (subselect) b WHERE a.id = b.id+10
>
> but without performing the subselect twice
> ..................................?

You have to write the subselect twice if you want to match up different rows.
In some cases it might be worth making a copy in a temp table. For simple
subselects where there is an index on id, leaving it as is should work fine.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Max 2005-01-27 05:46:36 Re: Splitting queries across servers
Previous Message Max 2005-01-27 05:36:37 Re: Splitting queries across servers