INSERT INTO departmentreport (departmentreport.departmentName,departmentreport.employeeCount) SELECT distinct departments.name, count(employees.id) as totalEmployees FROM departments INNER JOIN employees ON departments.id = employees.departmentId GROUP by departments.name having totalEmployees>0