Re: outer joins

Поиск
Список
Период
Сортировка
От Jeff Boes
Тема Re: outer joins
Дата
Msg-id 42F3DAAA.4030306@endpoint.com
обсуждение исходный текст
Ответ на Re: outer joins  ("D Kavan" <bitsandbytes88@hotmail.com>)
Список pgsql-admin
D Kavan wrote:

> There are 66 project id's in the project table and 3 rows in the
> project_members table for global_id 2915, but it only returns 3.  I
> would think it should return 66 rows, with 63 of them having a null
> pm.project_id.
>
> SELECT
>       p.project_id, pm.project_id
>       FROM project p
> LEFT OUTER JOIN project_members pm ON p.project_id = pm.project_id
> where (pm.project_id is null or pm.global_id = 2915)
>

It would return 66, if all 66 p.project_id's were _missing_ from the set
of pm.project_id's.

A "LEFT JOIN" asks for all the rows in the left-hand table (p), joined
to all the matching or missing rows in the right-hand table (pm). Then
your "WHERE" clause filters all those but the missing ones OR the ones
with global_id 2915.

You need to check on the data with something like:

select distinct project_id from project;
select distinct project_id from project_members;


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

Предыдущее
От: "Jason Minion"
Дата:
Сообщение: Re: outer joins
Следующее
От: Stephan Szabo
Дата:
Сообщение: Re: outer joins