title: Mysql query to get total childs?
body: <p>I have a 4 tables in which i need to fetch users info, state name , branch name and total no of childs from db. </p>
  
  <p>I used below sql</p>
  
  <pre><code>SELECT  `user_id` ,  `user_name` , state_name, branch_name
  FROM  `user` 
  LEFT JOIN state ON state_id = user_state_id
  LEFT JOIN branch ON branch_id = user_branch_id
  </code></pre>
  
  <p>But i also need to get count of childs for each user so i used below query</p>
  
  <pre><code>SELECT  `user_id` ,  `user_name` , state_name, branch_name, count(child_id)
  FROM  `user` 
  LEFT JOIN state ON state_id = user_state_id
  LEFT JOIN branch ON branch_id = user_branch_id
  LEFT JOIN child on parent_id = user_id  group by user_id
  </code></pre>
  
  <p>I need to ask one question it it ok to use group by for count in whole query Is this affect data which come with joins from this query</p>