select x.dept_no, x.emp_no, x.salary as maxSalary FROM (SELECT de.dept_no, de.emp_no, s.salary, row_number()over(partition by de.dept_no order by s.salary desc)as mm from dept_emp de LEFT JOIN salaries s on s.emp_no = de.emp_no)x where x.mm =1 order by x.dept_no