Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 49A10633F8A for ; Tue, 16 Jun 2009 18:40:23 -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 80008-01 for ; Tue, 16 Jun 2009 18:40:21 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.183]) by mail.postgresql.org (Postfix) with ESMTP id E77D8632894 for ; Tue, 16 Jun 2009 18:40:21 -0300 (ADT) Received: by wa-out-1112.google.com with SMTP id m16so1003416waf.19 for ; Tue, 16 Jun 2009 14:40:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=9fHBdZNP+Sd4g+NBLHgaq2vRJsxHs3qeJ6ilx/gZgVw=; b=mE8GutHRM1mlGd+6wvLtWJGnyPvwHUe4rcF4eeaL4vcON08wZPucA048KarUnRiUki 6cl35He/0PC8qG6LrhDV3yOUGGMwqI0cNSxvaluIHVxwQW9SK6g9eUtdooNk/QoTgpX9 2jmvmkEzBZ9wMdlMol9JBmnJGg227CoJdmujs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=Kur5SPPT+hbIxjOEDioKs1UqPzd0hWXQ/TSvSZDc5sphxnlCgMZYsMBZfIpYExjyNA o0q4z7TokqcZF64nMxQ6OvQZ+dSq6ukkaPhBQajrWOha6WOxOJKwO+ouYD7fUGaunQKS vQxSfBWyKpvei24IcXNc8zj64o54D/16lgcFA= Received: by 10.115.46.10 with SMTP id y10mr14284040waj.61.1245188420478; Tue, 16 Jun 2009 14:40:20 -0700 (PDT) Received: from ?172.16.1.32? ([208.187.158.94]) by mx.google.com with ESMTPS id n9sm1793347wag.23.2009.06.16.14.40.19 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 16 Jun 2009 14:40:20 -0700 (PDT) Message-ID: <4A38114B.7090106@gmail.com> Date: Tue, 16 Jun 2009 15:40:27 -0600 From: Rob Sargent User-Agent: Thunderbird 2.0.0.21 (X11/20090318) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: left outer join on more than 2 tables? References: <4A3807CF.90109@consumercontact.com> <396486430906161425i1cb7949enff5443cc2043805a@mail.gmail.com> In-Reply-To: <396486430906161425i1cb7949enff5443cc2043805a@mail.gmail.com> 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/76 X-Sequence-Number: 32681 Richard Broersma wrote: > On Tue, Jun 16, 2009 at 1:59 PM, Carol > Cheung 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)?