mysql - Return zero instead NULL in subquery -
i need count posts each author. i'm using subquery count them. author has not post, result null, wish 0.
select id, name, (select count(id) posts post.author = authors.id group author) post_num authors order post_num desc how can solve problem?
use coalesce:
select id, name, coalesce((select count(id) posts post.author = authors.id group author), 0) post_num authors order post_num desc
Comments
Post a Comment