select dept_no, emp_no, salary maxSalary from ( select d.emp_no emp_no, d.dept_no dept_no, s.salary salary, rank() over(partition by d.dept_no order by s.salary desc) rk from dept_emp d join salaries s on d.emp_no = s.emp_no ) a where a.rk=1 order by dept_no;