pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: Matthew Nuzum <cobalt@bearfruit.org>
To: pgsql-sql@postgresql.org
Subject: Re: simple join problem
Date: Wed, 19 Feb 2003 12:49:26 -0800
Message-ID: <200302191249.26342.josh@agliodbs.com> (raw)
In-Reply-To: <000501c2d848$002317e0$6900a8c0@mattspc>
References: <000501c2d848$002317e0$6900a8c0@mattspc>

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




view thread (7+ messages)  latest in thread

Message-ID: <200302191249.26342.josh@agliodbs.com>
Permalink:  ../200302191249.26342.josh@agliodbs.com/
Also on:    postgresql.org/message-id/200302191249.26342.josh@agliodbs.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: josh@agliodbs.com, cobalt@bearfruit.org
  Subject: Re: simple join problem
  In-Reply-To: <200302191249.26342.josh@agliodbs.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox