Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 Self Joins

Author  Topic 

mdixon44
Starting Member

26 Posts

Posted - 2009-02-15 : 21:46:00
I am confused on this question and I need a little assistance

Determine if any employee is working for a manager who was hired after that employee was hired. Show the employee_id, first_name, and hire_date of both the employee and the manager.

This is what I have come up with

select emp.employee_id
emp.first_name,
emp.hire_date,
boss.employee_id
boss.hire_date
from l_employees emp
left outer join l_employees boss
on emp.manager_id = boss.employee_id;

My Problem is getting the hire date to show correctly for the employee and the manager.

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-15 : 22:10:11


Select emp.employee_id
emp.first_name,
emp.hire_date,
boss.employee_id
boss.hire_date
from l_employees emp
left outer join l_employees boss
on emp.manager_id = boss.employee_id and boss.hiredate > emp.hiredate
Go to Top of Page
   

- Advertisement -