pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rob Sargent <robjsargent@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: left outer join on more than 2 tables?
Date: Tue, 16 Jun 2009 15:40:27 -0600
Message-ID: <4A38114B.7090106@gmail.com> (raw)
In-Reply-To: <396486430906161425i1cb7949enff5443cc2043805a@mail.gmail.com>
References: <4A3807CF.90109@consumercontact.com>
	<396486430906161425i1cb7949enff5443cc2043805a@mail.gmail.com>

Richard Broersma wrote:
> On Tue, Jun 16, 2009 at 1:59 PM, Carol
> Cheung<cacheung@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)?



view thread (8+ messages)  latest in thread

Message-ID: <4A38114B.7090106@gmail.com>
Permalink:  ../4A38114B.7090106@gmail.com/
Also on:    postgresql.org/message-id/4A38114B.7090106@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: robjsargent@gmail.com
  Subject: Re: left outer join on more than 2 tables?
  In-Reply-To: <4A38114B.7090106@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox