dbTalk Databases Forums  

Joins

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Joins in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Russell Shaw
 
Posts: n/a

Default Joins - 02-02-2004 , 09:46 AM






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:

Table1, Parts:

part man_id case_id desc_id
------------------------------
text int int int

Table2: Manufacturers:

man_id manufacturer
--------------------
int text

Table3, Cases:

case_id case
-------------
int text

Table4, Descriptions:

desc_id description
--------------------
int text


Is this right? :

SELECT part, manufacturer, case, description
FROM parts LEFT OUTER JOIN manufacturers, cases, descriptions
NATURAL


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


Reply With Quote
  #2  
Old   
Nabil Sayegh
 
Posts: n/a

Default Re: Joins - 02-03-2004 , 04:48 PM






Russell Shaw wrote:
Quote:
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);

[...]

Quote:
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

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.