Re: Joins

From: Nabil Sayegh <postgresql(at)e-trolley(dot)de>
To: Russell Shaw <rjshaw(at)iprimus(dot)com(dot)au>, pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Joins
Date: 2004-02-03 22:48:55
Message-ID: 40202557.3030003@e-trolley.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Russell Shaw wrote:
> Hi,
> I'm trying to get a list of all the rows in the Parts table, with
> the integer indexes of man_id, case_id, and desc_id, replaced with text
> from their respective tables. In the Parts table, any of man_id, case_id,
> and desc_id may be absent:

Something like that? :^)

SELECT * FROM parts LEFT OUTER JOIN manufacturers USING (man_id) LEFT OUTER JOIN cases USING
(case_id) LEFT OUTER JOIN descriptions USING (desc_id);

[...]

> Is this right? :
>
> SELECT part, manufacturer, case, description
> FROM parts LEFT OUTER JOIN manufacturers, cases, descriptions
> NATURAL

Hm, don't know if that syntax is correct, but LEFT OUTER JOIN is indeed what you want.
But I don't recomment NATURAL as there may be columns with the same name which you don't want to
join on. I suggest always specify "USING (fieldname)" or "ON (tab1.col1=tab2.col2)".
You can also specify whole subqueries in the ON (...) part.

HTH
--
e-Trolley Sayegh & John, Nabil Sayegh
Tel.: 0700 etrolley /// 0700 38765539
Fax.: +49 69 8299381-8
PGP : http://www.e-trolley.de

In response to

  • Joins at 2004-02-02 15:46:41 from Russell Shaw

Browse pgsql-novice by date

  From Date Subject
Next Message Nabil Sayegh 2004-02-03 22:52:16 Re: Inserting a Null date.
Previous Message chris 2004-02-03 01:02:18 Re: Can a user change their own password?