Solved: Help with JOIN statement (SQL Server)
I am having trouble setting up a Join statement and am not getting the desired results.
This is for SQL Server.
I have a table for employees and a table for training. The PK on employees = the FK on training.
So something like this:
TblEmployees
PK Name
1 Name1
2 Name2
3 Name3
TblTraining
PK FK Category Expiration
1 1 Category 1
2 1 Category 2
3 2 Category 2
4 2 Category 3
5 3 Category 2
So I want to get the expiration date where Category = "Category 1".
So I have this:
Code:
SELECT E.Name, T.Expiration
FROM TblEmployees AS E
LEFT OUTER JOIN
TblTraining AS T ON E.PK=T.FK
WHERE T.Category='Category 1'
Now in the example data above only Employee "Name1" has Training "Category 1". And that is the only result that I get. What I want to get is all the employees from the Employees table and if there is no matching training 1 in the Training table then the Expiration field should be Null.
That is what I expected the Left Join to do but it is not returning the results that dont have a match in TblTraining.
I would like to get:
Name1 SomeDate
Name2 Null
Name3 Null
Thanks