One Mentor may mentor several Mentees in a 1:N relationship which is optional on both ends, therefore there may be managers who don't mentor any other managers and also managers who are not mentored by another manager. Both Mentors and Mentees are represented by their respective Number which is also their Manager Number from the Manager table.
The Employee table has the following columns:
The Manager table contains:
The Mentor table contains:
I am trying to do a JOIN so that I can see following columns:
I have the following join statement, which does not seem to work and I am unsure why:
SELECT
man.manager_number,
man.employee_number AS mentor_employee,
emp.name AS mentor_name,
man2.employee_number AS mentee_employee,
emp2.name AS mentee_name
FROM
manager man
INNER JOIN
employee emp
ON
emp.employee_number = man.employee_number
INNER JOIN
mentor men
ON
man.manager_number= men.mentor_number
INNER JOIN
employee emp2
ON
emp2.employee_number = man2.employee_number
INNER JOIN
mentor men
ON
man.manager_number= men.mentee_number;
Any help would be greatly appreciated!
Keeping aside the logic you need, you have some issues to fix:
ON
emp2.employee_number = man2.employee_number /* <---- no MAN2 alias */
INNER JOIN
mentor men /* <---- same alias MEN than before */
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.