Re: How Do You Do a Three Way Join?

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: kvnsmnsn(at)cs(dot)byu(dot)edu
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: How Do You Do a Three Way Join?
Date: 2007-05-22 16:32:07
Message-ID: 20070522092729.P28328@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice


On Tue, 22 May 2007 kvnsmnsn(at)cs(dot)byu(dot)edu wrote:

> I've got three tables, <jqz>, <zqj>, and <abc>. I can do a
> <jqz j RIGHT JOIN zqj z> and a <zqj z LEFT JOIN abc a>, but is there a
> way to do a three-way join to get the columns of all three tables? Of
> course I could do one of those former two joins and then join the out-
> put table to the third table, but is there a way to do it without cre-
> ating the intermediate table?
>
> I tried:
>
> SELECT
> j.abc, j.def, z.xyz, a.ghi
> FROM
> jqz j RIGHT JOIN zqj z LEFT JOIN abc a
> ON
> j.abc = z.abc AND z.xyz = a.xyz;

I think you'd want something like
(jqz j RIGHT JOIN zqj z ON j.abc=z.abc) LEFT JOIN abc a ON (z.xyz=a.xyz)

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message David Monarchi 2007-05-22 20:20:58 reading table metadata from pl/pgsql in 8.2 under FreeBSD
Previous Message Richard Broersma Jr 2007-05-22 16:05:50 Re: How Do You Do a Three Way Join?