Re: Joining several tables

Lists: pgsql-sql
From: Stephan Richter <srichter(at)cbu(dot)edu>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Joining several tables
Date: 2001-01-22 06:20:14
Message-ID: 4.3.1.0.20010122001803.00a99dd0@198.78.130.6
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Hello, I have the following situation:

I have an Address, PhoneNumber and Contact table all having a contactid in
common, but sometimes the phone number does not exist.

I want to join these three tables. How do I do that? I could not find the
syntax for multiple tables...

Regards,
Stephan
--
Stephan Richter
CBU - Physics and Chemistry Student
Web2k - Web Design/Development & Technical Project Management


From: "PM" <pmeloy(at)home(dot)negate(dot)spam(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Joining several tables
Date: 2001-01-23 03:35:50
Message-ID: 94itt6$1cmu$1@news.tht.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

As long as the contactid is not null in any of the tables its easy. You
didn't give any column name information so I'll wing it. Not knowing the
relationships between the tables means this might get you a fair amount of
repeat data. If there is only ONE row in each table for a given contactid
it'll work ok.

SELECT street,phone,contname FROM Address a, PhoneNumber p, Contact c WHERE
a.contactid=p.contactid and a.contactid=c.contactid;

I have no affiliation with cold remedy manufacturers (heh, Contact c...)

"Stephan Richter" <srichter(at)cbu(dot)edu> wrote in message
news:4(dot)3(dot)1(dot)0(dot)20010122001803(dot)00a99dd0(at)198(dot)78(dot)130(dot)6(dot)(dot)(dot)
> Hello, I have the following situation:
>
> I have an Address, PhoneNumber and Contact table all having a contactid in
> common, but sometimes the phone number does not exist.
>
> I want to join these three tables. How do I do that? I could not find the
> syntax for multiple tables...
>
> Regards,
> Stephan
> --
> Stephan Richter
> CBU - Physics and Chemistry Student
> Web2k - Web Design/Development & Technical Project Management
>