Re: self outer join

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: David Link <dlink(at)soundscan(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: self outer join
Date: 2001-11-06 17:22:07
Message-ID: 20011106091826.E44948-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Tue, 6 Nov 2001, David Link wrote:

> Hi,
>
> In pg 7.1 using the new outer join syntax.
>
> SELECT *
> FROM t1 LEFT OUTER JOIN t2 ON (t1.col = t2.col);
>
> or
>
> SELECT *
> FROM t1 LEFT OUTER JOIN t2 USING (col);
>
> How does one specify an alias for the table being joined. This is
> important if you are creating an outer join to the same table:
>
> Oracle syntax (simplified) would be:
>
> select r.key,
> r.rank,
> r2.rank as last_weeks_rank
> from rank r,
> rank r2
> where r.key = (+)r2.key and
> r2.week = r1.week - 1
> ;

I think (untested)
select r.key, r.rank, r2.rank as last_weeks_rank
from (rank r left outer join rank r2 using (key))
where r2.week=r1week-1;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2001-11-06 17:30:31 Re: Howto change column length
Previous Message Paul Laub 2001-11-06 17:15:08 Null value representation in the array data structure