pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rudi Starcevic <rudi@oasis.net.au>
To: pgsql-sql@postgresql.org
Subject: Re: Count equals 0
Date: Thu, 20 Mar 2003 15:38:48 +1000
Message-ID: <3E7953E8.9090800@oasis.net.au> (raw)
References: <ea0824a43c82b86591e6b913514cf5ba@biglumber.com>

Hi,

Thank you kindly for your suggetions.
Greg's suggestion was closest to what I needed ( spot on in fact )

Cheers
Rudi.

greg@turnstep.com wrote:

>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>
>  
>
>>I've tries Left outer join's with and without coalesce without joy so far.
>>Please check out my query.
>>    
>>
>
>Your query is good, let's just make the whole thing a subselect
>and use an outer join to get the missing sites:
>
>SELECT u2.site_name, COALESCE(u1.total, 0)
>FROM
>(
>   SELECT  site_name, COUNT(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 site_name
>) AS u1
>RIGHT OUTER JOIN user_main u2 USING (site_name)
>GROUP BY 1,2
>ORDER BY u2.site_name;
>
>
>You could also write this as a LEFT OUTER JOIN (by putting the subselect second), 
>but I think it is clearer if the USING or ON is as close as possible to the 
>JOIN statement.
>
>
>- --
>Greg Sabino Mullane greg@turnstep.com
>PGP Key: 0x14964AC8 200303181009
>
>-----BEGIN PGP SIGNATURE-----
>Comment: http://www.turnstep.com/pgp.html
>
>iD8DBQE+dzbwvJuQZxSWSsgRAj5FAJ4s2ZJgaBm8g4otdHHNI6VkhoElsgCg0Bkb
>drxn19A1moxzQbAFy3Jv+Dc=
>=tImk
>-----END PGP SIGNATURE-----
>
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>
>  
>

view thread (5+ messages)

Message-ID: <3E7953E8.9090800@oasis.net.au>
Permalink:  ../3E7953E8.9090800@oasis.net.au/
Also on:    postgresql.org/message-id/3E7953E8.9090800@oasis.net.au

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: rudi@oasis.net.au
  Subject: Re: Count equals 0
  In-Reply-To: <3E7953E8.9090800@oasis.net.au>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox