Re: joining from multiple tables

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: joining from multiple tables
Дата
Msg-id 20030115180057.B97388-100000@megazone23.bigpanda.com
обсуждение исходный текст
Ответ на joining from multiple tables  (Joseph Shraibman <jks@selectacast.net>)
Список pgsql-sql
On Wed, 15 Jan 2003, Joseph Shraibman wrote:

> select distinct n.thekey, n.val, t.txt  FROM  num_tab n LEFT JOIN txt_tab t ON n.thekey =
> t.thekey
> WHERE  n.thekey < 5 AND t.class = class_tab.tkey AND n.class = class_tab.class;
> produces:

Note that the above uses the non-standard postgres behavior of adding from
clauses, it's not technically valid SQL.

>   thekey | val | txt
> --------+-----+------
>        2 |   2 | two
>        4 |   4 | four
> ... which is not what we want, because 1,3, and 5 aren't included, but:
>
> select distinct n.thekey, n.val, t.txt  FROM  num_tab n LEFT JOIN txt_tab t ON n.thekey =
> t.thekey  AND t.class = class_tab.tkey AND n.class = class_tab.class
> WHERE  n.thekey < 5;
>   produces:
> NOTICE:  Adding missing FROM-clause entry for table "class_tab"
> ERROR:  JOIN/ON clause refers to "class_tab", which is not part of JOIN
>
> So how do I do this?

I think you want something like:

select distinct n.thekey, n.val, t.txt  FROM class_tab JOIN num_tab n
using (class) LEFT JOIN txt_tab t on (t.thekey=n.thekey and t.class =
class_tab.tkey);



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

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: RFC: A brief guide to nulls
Следующее
От: Ludwig Lim
Дата:
Сообщение: Re: RFC: A brief guide to nulls