I am using a subquery to count some sub category count values. But some times it does not have any count value. At that case my quesry update field value as null. Instead of that I need to update it as zero. How can I check whether the subquery result is null or not not inside sp?
I tried like this but it is not working.
SELECT
if(sum(sub_category),sum(sub_category),0)
FROM myobjectcount
WHERE 1
GROUP BY category_id
The IFNULL() control flow function is a very handy MySQL function. Tends to help avoid writing nasty CASE statements!
Also – the
where 1predicate is rather unusual. It seems superfluous to me so I have left it out.