COUNT of rows with parent id equal to the row we have with a parent id of 0 in one query
This is easily achievable with an in-line subquery :

select  m.id,
        (select count(*) from messages where parent_id= m.id ) as ChildCount
from messages m
where m.parent_id = 0


Note that no group by is needed because a sub-query is used.