select a.* ,b.dept_no
from
salaries a inner join dept_manager b
on a.emp_no=b.emp_no and a.to_date =b.to_date
order by a.emp_no