Hello, again,
Hopefully, this is an easier solution.
I have the following two tables:
CREATE TABLE [dbo].[Directors](
[DeptNum] nvarchar NULL,
[DeptName] nvarchar NULL,
[EmpName] nvarchar NULL,
[DirectorID] nvarchar NULL
CREATE TABLE [dbo].[EmployeeTable](
[Department] nvarchar NULL,
[DeptNum] nvarchar NULL,
[EmpName] nvarchar NULL,
[EmpNum] nvarchar NOT NULL,
[State] nvarchar NULL,
[City] nvarchar NULL,
[Zip] nvarchar NULL,
[Email] nvarchar NULL
The table called Directors displays all Directors and the departments they are responsible for.
A Director can be responsible for one or more departments.
Then the second table called EmployeeTable contains records of ALL employees and Directors are also employees on this table and there is one record for each employee based on employee id called empnum.
Employee Id on Directors table is called DirectorID and it is a foreign key to employeeTable table based on empnum.
What I have been trying to do is display a Director's record by joining the two tables.
If a Director, as indicated earlier, has more than one department in Directors table, display that Director's record with those departments associated with the Director.
I have attempted LEFT JOIN but I just keep getting only one department.
What am I doing wrong?
Thanks a lot in advance.
select h.DirectorID,
e.DeptNum,
e.Department,
e.EmpName as EmployeeName,
e.empnum,
e.Email,
e.zip
FROM EmployeeTable e
LEFT JOIN Directors h on e.empnum = h.directorId
WHERE h.directorid = '9884476'
AND e.Password = 'T400s'
- List item