Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In article <4A425379.90907@xxxxxxxxxxx>,
Madison Kelly <linux@xxxxxxxxxxx> 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.


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux