Not sure if this is needed as well:
Relationships:
MANAGER_EMPLOYEES.employee_id -> EMPLOYEES.employee_id
MANAGER_EMPLOYEES.manager_employee_id -> EMPLOYEES.employee_id
EMPLOYEE_SALARAIES.employee_id -> EMPLOYEES.employee_id
Sure looks like some type of homework or assignment, so I won't give full answers.
But you do need to use LEFT JOIN instead of INNER JOIN for most of these. #4 will require a GROUPing of some type, the others not.
1 Like
It is an assignment for a summer class and all resources (and answers) are welcome!
I got this for number 1, but it isn't showing the manager name:
SELECT employees.employee_name
FROM employees
left join manager_employees
on employees.employee_id = manager_employees.employee_id;
You need to explicitly list every column you want to see, something like this:
SELECT e.employee_name, ISNULL(me.manager_employee_id, 'NONE') AS manager_employee_id
FROM employees e
left join manager_employees me
on e.employee_id = me.employee_id;
If you need to change the mgr's id to a name, you'll have to look it up back in employees ... that's where the alias I added to the table names is critical, because it allows you to reference the same table twice in the same query and be able to tell the columns from each reference apart.