Reputation: 3
I'm somewhat new to SQL, so I appreciate any help!
I have 3 tables that I'm working with here:
Employees
Projects
Tasks
I'm needing to build a query that shows the Task Name, Manager's name and Employee Name. The ManagerID is the same ID as an EmployeeID from the Employee table and EmployeeID on Tasks is the same as the ID for that employee on the EmployeeID table.
I know how to build the query to get everything in as an ID, but I'm not sure how to bring in the Employee Names since one table holds the name for both the Employee and the Manager.
Here is my current query:
Select t.TaskName,
t.EmployeeID,
p.ManagerID
From Tasks as t
Inner join projects as p on p.ProjectId = t.ProjectID
Upvotes: 0
Views: 772
Reputation: 859
Join the Employees table to your query twice, giving each a different alias:
Select t.TaskName,
e1.EmployeeName as Manager,
e2.EmployeeName as Employee
From Tasks as t
Inner join Projects as p on p.ProjectId = t.ProjectID
Inner join Employees as e1 on p.ManagerID = e1.EmployeeID
Inner Join Employees as e2 on t.EmployeeID = e2.EmployeeID
Hope this helps.
Upvotes: 1