Re: Joining on a column that might be null

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "James McMurry" <jmcmurry(at)pobox(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Joining on a column that might be null
Date: 2001-02-28 04:00:50
Message-ID: 16739.983332850@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

"James McMurry" <jmcmurry(at)pobox(dot)com> writes:
> item.created_by contains entries from member.member_id, and I'd like to
> select records from item with the full member_name:
> select a.item_id, a.item_name, b.member_name
> from item a, member b
> where a.created_by = b.member_id
> The problem I'm having is that created_by can be null. The above statement
> won't give me results for those records.

I believe what you're looking for is an "outer join". We have this for
real in PG 7.1, but in earlier releases you have to fake it with a UNION
construct. See http://www.postgresql.org/docs/faq-english.html#4.24

regards, tom lane

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Allen.Kimberly 2001-02-28 15:45:18 postgres 6.5.2 questions
Previous Message Andy Arledge 2001-02-28 02:51:24