Re: Making Count(*) return zero
Date: Thu, 10 Dec 2009 04:12:33 -0800 (PST)
Message-ID: <af1de005-fedb-4d7e-abc4-ec169259cc2f_at_n35g2000yqm.googlegroups.com>
On Dec 9, 7:41 pm, Gints Plivna <gints.pli..._at_gmail.com> wrote:
> > 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
>
> Scalar subqueries as already said or left join as follows:
> select userid, count(sometable.val)
> from users left join sometable
> on (users.userid = sometable.val)
> group by userid
>
> Gints Plivnahttp://www.gplivna.eu
Thank you all for your reply, but actually I need to be more precise
on the issue:
My sql sentence is going like this:
from Service
select ID,count(*)
where ID in (51,55,73)
and (InicialDate is null or InicialDate > '09/12/2008')
group by ID
resulting in :
ID Column2
- ---------- 55 11454 73 1
What I need is :
ID Column2
- ---------- 51 0 55 11454 73 1
Thank you all. Received on Thu Dec 10 2009 - 13:12:33 CET