left outer join on more than 2 tables?

Поиск
Список
Период
Сортировка
От Carol Cheung
Тема left outer join on more than 2 tables?
Дата
Msg-id 4A3807CF.90109@consumercontact.com
обсуждение исходный текст
Ответы Re: left outer join on more than 2 tables?  (Richard Broersma <richard.broersma@gmail.com>)
Re: left outer join on more than 2 tables? (UNCLASSIFIED)  ("Hall, Crystal M CTR DISA JITC" <Crystal.Hall.ctr@disa.mil>)
Список pgsql-sql
Hi,
I have 3 tables

region:
id
region_name

city:
id
city_name
region_id

complaint:
id
date
city_id

I would like to find the counts of complaints by region and I would like 
all regions to be displayed, regardless of whether or not complaints 
exist for that region. Is left outer join what I'm looking for?
I'm stuck at this point:
select r.region_name, count(1) from region r left outer join city c, 
complaint k on (k.city_id = c.id and r.id = c.region_id) group by 
r.region_name
Of course this doesn't work ...
Can anyone provide their insight as to how I can achieve this?

Thanks in advance,
C


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

Предыдущее
От: Andy Shellam
Дата:
Сообщение: Re: PHP pg_escape_string
Следующее
От: Richard Broersma
Дата:
Сообщение: Re: left outer join on more than 2 tables?