I have a problem about database table and query of it. Let me tell what this is about. It is about project-manager-employee relationship. Now Let me tell in statements what their relationship...
Manager = Manager is a project leader or could be manager of MORE than ONE project.
Employee = (s)He is a person who only works on project or projectS which is managed by Manager.
Project= Project is a project which managed by only ONE Manager.
Employee - Manager Relationship
Manager is also a employee in company right? According to this I want their relationship like -> one Employee can be managed by more than ONE Manager.
All managers are in the same title I mean there is no manager of a manager. There is only manager(s) for an employee. For example 5 employees can be managed by a Manager.
Employee - Project Relationship
Employee can have a project that make sense, also employee can have more than ONE project that's make sense too. So project can have more than ONE employee too. (reminder: Project can have more than ONE Employee, BUT can NOT be managed by more than ONE Manager).
Manager - Project Relationship
Manager can have more than ONE project. BUT Project can NOT be managed by more than ONE Manager.
PS: According to project, same employee in different projects CAN BE managed by more than one manager See my example below...
Android App PROJECT's Manager----> Patrick
Android App PROJECT's Employees-----> John, Susan, Megan, Joe.
Another Project...
IOS App PROJECT's Manager----> Ryan
IOS App PROJECT's Employees----> Claire, Walter, Robert, Megan
Now let me show my tables for that... I can't really know what should I do...
In that table I tried to do that "manager_id(FK)" refer to "employee_id(PK)" because Manager is a employee in company.
And I have "manager_id(FK)" in Project table to refers "manager_id" in employee table.
And which is proj_employee table I didn't clearly understand. I found this way in examples from internet. That way we call them in query.
NOW let me post my queries I tried but never get a solution...
select
e.name as employee_name,
pm.name as manager_name
from Proj_Employee as pe
left outer join Employee as e on e.employee_id = pe.emp_id
left outer join Project as p on p.project_id = pe.project_id
left outer join Employee as pm on pm.employee_id = p.manager_id
where pe.project_id = <project id>
I would like to ask this... I want a query which shows me EmployeeName, ManagerName OF choosen project. And if my table is wrong Could you guide me or tell me how can I do that?
I have knowledge but couldn't figure it out how can I make this work.