Re: Optional join

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: Optional join
Дата
Msg-id 20030814213916.S5124-100000@megazone.bigpanda.com
обсуждение исходный текст
Ответ на Optional join  ("Slawek Jarosz" <Jarosz.S@ems-t.ca>)
Список pgsql-sql
On Thu, 14 Aug 2003, Slawek Jarosz wrote:

> 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 reults could be
> table1...   table2.pk2
> table1...   NULL

See outer joins.

Something like:
SELECT table1.*,table2.pk FROMtable1 LEFT OUTER JOIN table on (table2.f2=table1.pk1);



В списке pgsql-sql по дате отправления:

Предыдущее
От: Bruno Wolff III
Дата:
Сообщение: Re: Optional join
Следующее
От: "cristi"
Дата:
Сообщение: sequence