title: How can I select multiple rows with the count of other rows in the same table that has their primary keys in a separate column?
body: <p>I am trying to get the parent comments from my table and the count of its child comments from the same table-</p>
  
  <pre><code>comment_id    answer_id   comment_body  parent_id
      1            51       new comment     NULL
      2            51      child comment      1
      3            51         fgdfg           1
      4            51     another comment   NULL
  </code></pre>
  
  <p>expected output </p>
  
  <pre><code>comment_id    answer_id   comment_body  parent_id    childs
      1            51       new comment     NULL          2
      4            51     another comment   NULL          0
  </code></pre>
  
  <p>I tried this query </p>
  
  <pre><code>SELECT NULL AS childs,
      tbl_answer_comment.*
  FROM
      tbl_answer_comment
  WHERE
      tbl_answer_comment.parent_id = NULL
  UNION
  SELECT
      COUNT(tbl_answer_comment.parent_id) AS childs,
      tbl_answer_comment.*
  FROM
      tbl_answer_comment
  </code></pre>
  
  <p>But this only returns</p>
  
  <pre><code>comment_id    answer_id   comment_body  parent_id    childs
      4            51     another comment   NULL          2
  </code></pre>