Insert data into table from other tables in MySQL Query

 


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

Leave a Reply

Your email address will not be published. Required fields are marked *