title: MySQL: get total number of employees in each department
body: <p>I am new to MySQL and Have following question. </p>
  
  <p>Let's say I have two following tables</p>
  
  <p><strong>Departments</strong></p>
  
  <pre><code>DepartmentId    Name
  </code></pre>
  
  <p><strong>Employees</strong></p>
  
  <pre><code>ID    DepartmentId   Name
  </code></pre>
  
  <p>I have written following query which is returning half of my expected result</p>
  
  <pre><code>select
    d.name as departmentName,
    count(*) as totalEmployees
  
  from 
    employees e
  
  join department d
  on d.departmentId = e.departmentId
  
  group by
    d.departmentId,
    d.name
  </code></pre>
  
  <p>which returns the result with number of employees in each department. but I want to have following two cases in my query.</p>
  
  <pre><code>1. Some departments don't have employees
  2. Some departments have the same name
  </code></pre>
  
  <p>I have tried my query with <em>NOT EXISTS</em> and <em>NOT IN</em> but could not get expected result. Could anyone please help me here to cover above two cases in MySQL query.</p>