Hi there,
I got this difficult issue having two table where I wish to filter on the right table in a left outer join and have all rows return from the left and only those from the right that match, and if they dont match a NULL value is ok.
Department Table
DepartmentID DepartmentName
31 Sales
33 Engineering
34 Clerical
35 Marketing
Employee Table
LastName DepartmentID
Rafferty 31
Jones 33
Steinberg 33
Robinson 34
Smith 34
Jasper 36
A standard left outer join gives:
SELECT *
FROM employee E
LEFT OUTER JOIN department D
ON employee.DepartmentID = department.DepartmentID
E.LastName E.DepartmentID D.DepartmentName D.DepartmentID
Jones 33 Engineering 33
Rafferty 31 Sales 31
Robinson 34 Clerical 34
Smith 34 Clerical 34
Jasper 36 NULL NULL
Steinberg 33 Engineering 33
Trying to now implement a where clause to only get those employees in DepartmentID 33, but I still wish to list those that are not in that department, but only their information from the employee table. The result I hope to achieve:
E.LastName E.DepartmentID D.DepartmentName D.DepartmentID
Jones 33 Engineering 33
Rafferty 31 NULL NULL
Robinson 34 NULL NULL
Smith 34 NULL NULL
Jasper 36 NULL NULL
Steinberg 33 Engineering 33
Anyone know how to fix this?
I got this difficult issue having two table where I wish to filter on the right table in a left outer join and have all rows return from the left and only those from the right that match, and if they dont match a NULL value is ok.
Department Table
DepartmentID DepartmentName
31 Sales
33 Engineering
34 Clerical
35 Marketing
Employee Table
LastName DepartmentID
Rafferty 31
Jones 33
Steinberg 33
Robinson 34
Smith 34
Jasper 36
A standard left outer join gives:
SELECT *
FROM employee E
LEFT OUTER JOIN department D
ON employee.DepartmentID = department.DepartmentID
E.LastName E.DepartmentID D.DepartmentName D.DepartmentID
Jones 33 Engineering 33
Rafferty 31 Sales 31
Robinson 34 Clerical 34
Smith 34 Clerical 34
Jasper 36 NULL NULL
Steinberg 33 Engineering 33
Trying to now implement a where clause to only get those employees in DepartmentID 33, but I still wish to list those that are not in that department, but only their information from the employee table. The result I hope to achieve:
E.LastName E.DepartmentID D.DepartmentName D.DepartmentID
Jones 33 Engineering 33
Rafferty 31 NULL NULL
Robinson 34 NULL NULL
Smith 34 NULL NULL
Jasper 36 NULL NULL
Steinberg 33 Engineering 33
Anyone know how to fix this?