Re: Making Count(*) return zero

From: Bob Badour <bbadour_at_pei.sympatico.ca>
Date: Wed, 09 Dec 2009 16:27:45 -0400
Message-ID: <4b200843$0$5340$9a566e8b_at_news.aliant.net>


Guto wrote:

> Hi There!
>
> is there a way to make the count(*) return zero . because the default
> behavoir is that it will skip this value if there is no records so a
> simple query like this
>
> select userid,count(*) as count from users where userid in (select val
> from sometable)
> group by userid
>
> if userid 1 has no records . it wont be returned in the query
> instead i want it to show zero so
> userid count
> 1 0
> 2 3
> 3 1
> 4 0
>
> Any hints?
> Thanks!
> Guto.

Use a scalar subquery instead of just count(*) to calculate the [count] column.

-- 
is there something in it for them, like maybe bailouts, if they can 
panic us into doing something politically to cover them?

November 19, 2007 - John S Bolton

http://tinyurl.com/y9e4vxh
Received on Wed Dec 09 2009 - 21:27:45 CET

Original text of this message