Richard Broersma wrote:
On Tue, Jun 16, 2009 at 1:59 PM, Carol
Cheung<cache...@consumercontact.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;


Is there a city without a reference to region? And wouldn't you want to count(cm.id)?

--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

Reply via email to