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

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -