Optional join - Mailing list pgsql-sql

From Slawek Jarosz
Subject Optional join
Date
Msg-id sf3b6707.030@ems-t.ca
Whole thread Raw
Responses Re: Optional join  (Bruno Wolff III <bruno@wolff.to>)
Re: Optional join  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
Re: Optional join  (Ian Barwick <barwick@gmx.net>)
List pgsql-sql
Hi,
 I trying to write a query that will join 2 tables.   Here's the concept:
Table 1: table1, primary key pk1
Table 2: table2, primary key pk2

One of the fields (f2) in table2 contains either the primary key of table1 or a NULL value.  So normally a pretty basic
query:

SELECT table1.*, table2.pk2 FROM table1, table2 WHERE table2.f2 = table1.pk1;

BUT what I would like to do is show all records of Table 1 even if there is no match in Table 2.  Meaning that the
reultscould be  
table1...   table2.pk2
table1...   NULL

Doable?

Thanks.



pgsql-sql by date:

Previous
From: proghome@silesky.com (krystoffff)
Date:
Subject: Re: How to optimize this query ?
Next
From: Jomon Skariah
Date:
Subject: Re: Porting from PL/SQL to PLPGSQL