Reputation: 11
I am trying replace null with 0 with following statement but returns no recrods instead of of catid supplied and 0.
select ifnull(count(*),0) as days, catid from mytable where Id=48 and catId=7
group by mytable.catId;
Upvotes: 1
Views: 485
Reputation: 8355
As far as I know, COUNT(*) does never return NULL. It returns 0 if there is no record.
Upvotes: 3
Reputation: 1269533
count(*)
never returns NULL
, so you don't need any conditional logic:
select count(*) as days, catid
from mytable
where Id = 48 and catId = 7
group by mytable.catId;
Perhaps your issue is that the query is returning no rows. If so, you can leave out the group by
. Then the query will always return one row:
select count(*) as days, catid
from mytable
where Id = 48 and catId = 7 ;
Upvotes: 1