How to return 0 instead of null when using COUNT in MySQL

后端 未结 5 414

I am using this query to return return a list of songs stored in $sTable along with a COUNT of their total projects which are stored in $sTable2.

 /*
     * SQL          


        
5条回答
  •  失恋的感觉
    2021-01-27 07:45

    COALESCE() returns the first non-null argument. So if you say COALESCE(count(...),0) it will return the count(...) if it's not null, or it will return 0 if the count(...) is null

提交回复
热议问题