Re: Return LEFT JOINed tables when one has no matching column

From: Madison Kelly <linux(at)alteeve(dot)com>
To: Harald Fuchs <hari(dot)fuchs(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Return LEFT JOINed tables when one has no matching column
Date: 2009-06-24 18:16:44
Message-ID: 4A426D8C.4060309@alteeve.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Harald Fuchs wrote:
> In article <4A425379(dot)90907(at)alteeve(dot)com>,
> Madison Kelly <linux(at)alteeve(dot)com> writes:
>
>> SELECT
>> a.tbl1_name,
>> b.tbl2_date,
>> c.tbl3_value AS some_value
>> FROM
>> table_1 a
>> LEFT JOIN
>> table_2 b ON (a.tbl1_id=b.tbl2_tbl1_id)
>> LEFT JOIN
>> table_3 c ON (a.tbl1_id=c.tbl3_tbl1_id)
>> WHERE
>> c.tbl3_variable='some_variable'
>> AND
>> a.tbl1_id=123;
>
>> I want the data from table_1 and table_2 to return and table_3 to
>> return NULL when there is no matching
>> c.tbl3_variable='some_variable'. Is this possible?
>
> Move "c.tbl3_variable='some_variable'" from WHERE to c's ON clause.

Bingo, thank you!

Madi

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Mary Sipple 2009-06-24 18:25:35 fast shutdown
Previous Message Scott Marlowe 2009-06-24 18:16:33 Re: WAL and master multi-slave replication