pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gavin Baumanis <gavinb@eclinic.com.au>
To: Richard Broersma <richard.broersma@gmail.com>
Cc: Carol Cheung <cacheung@consumercontact.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: left outer join on more than 2 tables?
Date: Wed, 17 Jun 2009 07:39:50 +1000
Message-ID: <E8B4F516-1647-4621-B744-5DB66E1EC682@eclinic.com.au> (raw)
In-Reply-To: <396486430906161425i1cb7949enff5443cc2043805a@mail.gmail.com>
References: <4A3807CF.90109@consumercontact.com>
	<396486430906161425i1cb7949enff5443cc2043805a@mail.gmail.com>

At the risk of being wrong.... (I'm always ready to learn something  
new) - and seemingly I'm only too happy to be wrong!...

And... it might even be that it is exactly the same result - but I  
would have proposed;

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


Gavin.


On 17/06/2009, at 7:25 AM, 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;
>
>
> -- 
> Regards,
> Richard Broersma Jr.
>
> Visit the Los Angeles PostgreSQL Users Group (LAPUG)
> http://pugs.postgresql.org/lapug
>
> -- 
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql

As always Please contact me if I can be of any further assistance.

Gavin "Beau" Baumanis
Senior Application Developer
PalCare P/L

657 Nicholson Street
Carlton North
Victoria, Australia, 3054

E: beau@palcare.com.au
P: +61 -3 9380 3513
M: +61 -438 545 586
W: http://www.palcare.com.au



view thread (8+ messages)  latest in thread

Message-ID: <E8B4F516-1647-4621-B744-5DB66E1EC682@eclinic.com.au>
Permalink:  ../E8B4F516-1647-4621-B744-5DB66E1EC682@eclinic.com.au/
Also on:    postgresql.org/message-id/E8B4F516-1647-4621-B744-5DB66E1EC682@eclinic.com.au

 · 

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: gavinb@eclinic.com.au, richard.broersma@gmail.com, cacheung@consumercontact.com
  Subject: Re: left outer join on more than 2 tables?
  In-Reply-To: <E8B4F516-1647-4621-B744-5DB66E1EC682@eclinic.com.au>

* 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