Re: left outer join on more than 2 tables?

From: Richard Broersma <richard(dot)broersma(at)gmail(dot)com>
To: Carol Cheung <cacheung(at)consumercontact(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: left outer join on more than 2 tables?
Date: 2009-06-16 21:25:44
Message-ID: 396486430906161425i1cb7949enff5443cc2043805a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tue, Jun 16, 2009 at 1:59 PM, Carol
Cheung<cacheung(at)consumercontact(dot)com> wrote:
> 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?

SELECT R.region_name, Count(*) AS RegionComplaints
FROM Region AS R
LEFT JOIN City AS Ci
ON R.id = C.region_id
LEFT JOIN Complaint AS Cm
ON Ci.id = Cm.city_id
GROUP BY R.region_name;

--
Regards,
Richard Broersma Jr.

Visit the Los Angeles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Hall, Crystal M CTR DISA JITC 2009-06-16 21:27:21 Re: left outer join on more than 2 tables? (UNCLASSIFIED)
Previous Message Carol Cheung 2009-06-16 20:59:59 left outer join on more than 2 tables?