select dept_no, emp_no, salary from (select dept_no, a.emp_no, salary, max(salary)over(partition by dept_no order by dept_no) AS maxSalary from dept_emp a left join salaries b on a.emp_no = b.emp_no) tb_1 where salary = maxSalary