Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 3683B632A0B for ; Tue, 16 Jun 2009 18:18:35 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 75275-09 for ; Tue, 16 Jun 2009 18:18:33 -0300 (ADT) X-Greylist: delayed 00:17:14.595322 by SQLgrey-1.7.6 Received: from mail.consumercontact.com (mail.consumercontact.com [209.167.202.12]) by mail.postgresql.org (Postfix) with ESMTP id 16AD8632989 for ; Tue, 16 Jun 2009 18:18:34 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.consumercontact.com (Postfix) with ESMTP id EC7625904E0 for ; Tue, 16 Jun 2009 17:01:16 -0400 (EDT) X-Virus-Scanned: amavisd-new at consumercontact.com Received: from mail.consumercontact.com ([127.0.0.1]) by localhost (mail.consumercontact.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UCLxiWbyWZ9R for ; Tue, 16 Jun 2009 17:01:03 -0400 (EDT) Received: from [192.168.1.47] (mordred.consumercontact.com [192.168.1.47]) by mail.consumercontact.com (Postfix) with ESMTP id 5276759051B for ; Tue, 16 Jun 2009 17:00:40 -0400 (EDT) Message-ID: <4A3807CF.90109@consumercontact.com> Date: Tue, 16 Jun 2009 16:59:59 -0400 From: Carol Cheung User-Agent: Thunderbird 2.0.0.16 (Windows/20080708) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: left outer join on more than 2 tables? Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200906/73 X-Sequence-Number: 32678 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