SELECT dm.*, ds.sum FROM departments dm INNER JOIN ( SELECT d.dept_no, COUNT(*) AS sum FROM salaries s INNER JOIN dept_emp d ON s.emp_no = d.emp_no GROUP BY dept_no ) AS ds ON dm.dept_no = ds.dept_no ORDER BY dm.dept_no ASC
SELECT dm.*, ds.sum FROM departments dm INNER JOIN ( SELECT d.dept_no, COUNT(*) AS sum FROM salaries s INNER JOIN dept_emp d ON s.emp_no = d.emp_no GROUP BY dept_no ) AS ds ON dm.dept_no = ds.dept_no ORDER BY dm.dept_no ASC