CREATE TABLE `dept_emp` (
`emp_no` int(11) NOT NULL,
`dept_no` char(4) NOT NULL,
`from_date` date NOT NULL,
`to_date` date NOT NULL,
PRIMARY KEY (`emp_no`,`dept_no`));
CREATE TABLE `dept_manager` (
`dept_no` char(4) NOT NULL,
`emp_no` int(11) NOT NULL,
`from_date` date NOT NULL,
`to_date` date NOT NULL,
PRIMARY KEY (`emp_no`,`dept_no`));
select emp.emp_no,manager.emp_no as manager_no
from dept_emp as emp,dept_manager as manager
where
emp.emp_no != manager.emp_no
and emp.dept_no = manager.dept_no
and emp.to_date='9999-01-01'
and manager.to_date='9999-01-01'