I have EmployeeName
; it is from the Employee
table. The Employee
table holds ALL Employees in the organization and the Employee
table references the primary key of the Position
table, which holds the different position names. So this is how I'm differentiating between employees in the Employee
table; each record in the Employee
table has a PosNo
which references the Position table(worker = Pos1, manager = Pos2, etc...) So for simplicity's sake, a record in the employee table would be similar to: EmployeeName, EmployeeAddress, DeptNo, PosNo
Here's the problem: Certain positions are under other positions. There are workers in the Employee
table and there are managers in the Employee
table. I'm wanting to make a table that lists all workers and their managers. For example, the table would have two fields: EmployeeName, ManagerName
.
The Employee
table is broken down into a generalization hierarchy. The Salary
and Hourly
tables branch out from Employee
table. Then, from the Salary
table, another table branches out called Manager
(which I call ProgramSupervisor
; it has a unique field). Workers are part of the Hourly
table though. Managers(ProgramSupervisor
) and Workers(Hourly
) are related to each other through the ISL
table. The Manager is the head of the ISL and therefore ISL has a ManagerNo
as one of its fields. Workers(Hourly
), however, work in the ISL
and therefore have ISLNo
as a field in their table, the Hourly
table.
So, I'm trying to find a way to relate all of these table as make a table with two fields, workers and managers, in which the workers belong to managers through the ISL
table. Would I use a nested query of some sort? I'll post my code so far, which is absolutely not correct (probably no even on the right track) and I'll post my ERD so you can get a better picture of how the tables relate.
SELECT EmpLastName + ', ' + EmpFirstName as ProgSupName,
EmpLastName + ', ' + EmpFirstName as EmpName
FROM Employee, Salary, ProgramSupervisor, ISL, Hourly
WHERE Employee.EmpNo = Salary.EmpNo
AND Salary.EmpNo = ProgramSupervisor.EmpNo
AND ProgramSupervisor.EmpNo = ISL.ProgramSupervisor_EmpNo
AND ISL.ISLNo = Hourly.ISLNo
AND Hourly.EmpNo = Employee.EmpNo
ERD