Re: simple join problem

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: "Matthew Nuzum" <cobalt(at)bearfruit(dot)org>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: simple join problem
Date: 2003-02-19 20:49:26
Message-ID: 200302191249.26342.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Matthew,

> Can anyone demonstrate the correct syntax for joining several tables in this
> way?

Actually, there's several possible answers to your problem. Here's one:

>
> Here's my view definition:
> SELECT
> users.uid, users.loginid, users."password", users.title,
> users.firstname, users.middlename, users.lastname, users.suffix,
> users.organization, users.job_title, users_address.address1,
> users_address.address2, users_address.address3, users_address.city,
> users_address.state, users_address.zip, users_address.country,
> users_email.email, users_phone.phone
> FROM (((users
> LEFT JOIN users_address ON ((users.uid = users_address.uid AND
users_address.primary = TRUE)))
> LEFT JOIN users_email ON ((users.uid = users_email.uid and
users_email.primary = TRUE)))
> LEFT JOIN users_phone ON ((users.uid = users_phone.uid and
users_phone.primary = TRUE))) ;

It's a neat trick that join conditions can be *any* expression that evaluates
to a boolean value.

--
-Josh Berkus
Aglio Database Solutions
San Francisco

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message JBJ 2003-02-19 20:53:21 Re: once again, sorting with Unicode
Previous Message Guy Fraser 2003-02-19 20:37:32 Re: PL/PGSQL EDITOR