title: SQL Self Join with null values
body: <p>I am having all employees(manager and employees) under one table called Employee. Table looks as follows,</p>
  
  <h2><strong>Table</strong></h2>
  
  <pre><code>+-------+------------+---------+---------+------------+
  |emp_id | name       | dept_id | salary  | manager_id |
  +=======+============+=========+=========+============+
  |  1    | Sally      |   1     | 20000   |  null      |
  |  2    | Ajit       |   2     | 20000   |   1        |
  |  3    | Rahul      |   1     | 20000   |   1        |
  |  4    | uday       |   1     | 20000   |   null     |
  |  5    | john       |   1     | 20000   |   null     |
  |  6    | netaji     |   2     | 20000   |    2       |
  |  7    | prakriti   |   3     | 1111    |    3       |
  |  8    | sachin     |   3     | 1111    |    3       |
  |  9    | santosh    |   1     | 1111    |    2       |
  |  10   | Ravi       |   1     | 1111    |    2       |
  +-------+------------+---------+---------+------------+
  </code></pre>
  
  <p>Both managers and employees belong to same table. manager_id refers = emp_id who is manager. </p>
  
  <p>I want to write query to count number of employees belonging to each manager. So even if certain manager doesn't have any employee under her or him the count will show as 0</p>
  
  <p>Result should be as follows,</p>
  
  <h2><strong>Expected Output</strong></h2>
  
  <pre><code>+------+----------+
  |Count |  Manager |
  +======+==========+
  | 2    |  Sally   |
  | 3    |  Ajit    |
  | 2    |  Rahul   |
  | 0    |  Uday    |
  | 0    |  John    |
  +------+----------+
  </code></pre>