Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 1C57E633C12 for ; Tue, 16 Jun 2009 18:25:47 -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 76473-10 for ; Tue, 16 Jun 2009 18:25:45 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qy0-f195.google.com (mail-qy0-f195.google.com [209.85.221.195]) by mail.postgresql.org (Postfix) with ESMTP id C8B83632D27 for ; Tue, 16 Jun 2009 18:25:45 -0300 (ADT) Received: by qyk33 with SMTP id 33so5777035qyk.15 for ; Tue, 16 Jun 2009 14:25:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=n3Ku+lg8+UHQDKbWqDJH1nr2T3a6SmgBRcNAy1SStQQ=; b=LDu6KNjU9WosrrWecGkm3P0zpT4CEraSf/QQQ5OLS0lqLvIu8nnSLy8dVFlhSb7Mjo GwECLsn1XYJ/Mv4HMZuSF3c1RKErzXw2tkvsWgj+qFtc2EIo2ctZ5po74P8UpKozLeLd Jq32HVJqk6ZUj1zUy2bXlRMFXrZh4eTk/DVSw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=VUY1ieXT5JTbTp8x3Vin9X1fvIIESheatpJXEUoG/yVYC4nuVj9ougCLv9UU4dmowX GkN9H/oLxL2zJKzL8vqUl5faWVURqdbBFeRILNSUscPYeCYmksgDEZ/3KPWhU5kgpimp hM0LcLh4Z8LsDKOzxApMPp6VoP6YHCXwfPPwA= MIME-Version: 1.0 Received: by 10.220.72.78 with SMTP id l14mr6336976vcj.81.1245187544541; Tue, 16 Jun 2009 14:25:44 -0700 (PDT) In-Reply-To: <4A3807CF.90109@consumercontact.com> References: <4A3807CF.90109@consumercontact.com> Date: Tue, 16 Jun 2009 14:25:44 -0700 Message-ID: <396486430906161425i1cb7949enff5443cc2043805a@mail.gmail.com> Subject: Re: left outer join on more than 2 tables? From: Richard Broersma To: Carol Cheung Cc: pgsql-sql@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 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/74 X-Sequence-Number: 32679 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; -- Regards, Richard Broersma Jr. Visit the Los Angeles PostgreSQL Users Group (LAPUG) http://pugs.postgresql.org/lapug