not grokking outer joins...

From: will trillich <will(at)serensoft(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: not grokking outer joins...
Date: 2001-08-21 04:33:46
Message-ID: 20010820233346.A12955@serensoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

i'm trying to wrap outer joins around my cerebellum:

CUST:
id serial
name varchar(30)
ITEM:
cust integer references cust (id)
data varchar(30)
INFO:
cust integer references cust (id)
stuff text

for my query i'd like, for every customer, to have
item.* show up if it exists, and info.* show up
if it exists...

select
CUST.name,
ITEM.data,
INFO.stuff
from
CUST left join ITEM on (CUST.id=ITEM.cust),
CUST left join INFO on (CUST.id=INFO.cust)
.... not!

or does this need some subselect magic?

and (separate question) is there a way to be sure that ONE or the
OTHER or BOTH have joinable data, but don't show CUST if neither
ITEM nor INFO has a match?

foreach CUST
if ITEM matches
show record
elsif INFO matches
show record
else -- neither matches
dont show squat, not even from cust
end if
end foreach

--
Khan said that revenge is a dish best served cold. I think
sometimes it's best served hot, chunky, and foaming.
- P.J.Lee ('79-'80)

will(at)serensoft(dot)com
http://sourceforge.net/projects/newbiedoc -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrey Y. Mosienko 2001-08-21 04:48:57 Sort by foreign date column
Previous Message Kevin J. Drewiske 2001-08-21 03:52:37 RE: Printable report generation