X-Original-To: pgsql-sql@postgresql.org Received: from water.oasis.net.au (water.oasis.net.au [210.8.139.2]) by postgresql.org (Postfix) with ESMTP id 35D51474E4F for ; Tue, 18 Mar 2003 01:27:05 -0500 (EST) Received: from oasis.net.au (guardian [210.8.139.5]) by water.oasis.net.au (8.9.3/8.9.3/Debian 8.9.3-21) with ESMTP id QAA07730 for ; Tue, 18 Mar 2003 16:26:33 +1000 X-Authentication-Warning: water.oasis.net.au: Host guardian [210.8.139.5] claimed to be oasis.net.au Message-ID: <3E76BCB9.9070603@oasis.net.au> Date: Tue, 18 Mar 2003 16:29:13 +1000 From: Rudi Starcevic User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.1) Gecko/20020826 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Count equals 0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Archive-Number: 200303/423 X-Sequence-Number: 12462 Greetings, I have what I think is an easy query but is not working out for me. So I thought I'd ask .. I have 2 tables : user_main user_sys_messages In user_main I have many user's which belong to 3 web sites. In my admin tool I can send a user an email message and that message is logged to the user_sys_messages table. All that is good. What I want to report is those who have *not* recieved any email from me. If each of the 3 web site's has a user in user_main who has not recieved any messages the report form the below query looks like site a : 1 site b : 3 site c : 6 My problem is if a site has no one that has not recieved any message they do not appear in the report. Ie. site b : 3 site c : 6 What I would like to see is something like: site a : 0 site b : 3 site c : 6 I've tries Left outer join's with and without coalesce without joy so far. Please check out my query. Thank you kindly. -- new members --- members who haven't recieved any email from us SELECT um.site_name, count(um.cus_id) AS total FROM user_main um WHERE NOT EXISTS ( SELECT cus_id FROM user_sys_messages usm WHERE usm.cus_id = um.cus_id ) GROUP BY um.site_name ORDER BY um.site_name Regards Rudi.