Received: from smtp7.atl.mindspring.net (smtp7.atl.mindspring.net [207.69.128.51]) by hub.org (8.9.3/8.9.3) with ESMTP id WAA84505 for ; Wed, 18 Aug 1999 22:12:09 -0400 (EDT) (envelope-from postgres@mindspring.com) Received: from dyounger.internal.mindspring.com (fw-1-e2.hbg.mindspring.net [165.247.57.82]) by smtp7.atl.mindspring.net (8.8.5/8.8.5) with ESMTP id WAA05599 for ; Wed, 18 Aug 1999 22:12:08 -0400 (EDT) Message-Id: <4.2.0.58.19990818215523.00c808b0@proxy> X-Sender: (Unverified) X-Mailer: QUALCOMM Windows Eudora Pro Version 4.2.0.58 Date: Wed, 18 Aug 1999 22:10:35 -0400 To: pgsql-sql@postgresql.org From: Doug Younger Subject: Problems using count() with a join Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Hi, I have the following 2 tables: Table groups: g_id int4 g_name text Table users: u_id int4 g_id int4 What I want is to get a count of # of users in each group, even if there are no users in the group. I have tried the following: SELECT t1.g_name,count(t2.g_id) FROM groups t1,users t2 WHERE t1.g_id = t2.g_id GROUP BY t1.g_name; But it only give the counts of users in each group if there actually are users in that group. I want the count to be 0 if there are no users in the group. Thanks.