Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query to show records who haven't had paticular training 3

Status
Not open for further replies.

hsingh1981

Programmer
Apr 8, 2008
56
GB
Hi all i have query which shows all staff who had training using the course id. How do i find staff who haven't had training on a paticular courseid...such as course id = 5?


my current sql statement is:

Code:
SELECT dbo_Staff.Firstname, dbo_Staff.Surname, dbo_T_MandatoryTraining.TrainingDate, dbo_T_MandatoryTraining.CourseID
FROM dbo_Staff LEFT JOIN dbo_T_MandatoryTraining ON dbo_Staff.StaffID = dbo_T_MandatoryTraining.StaffID;

many thanks
 
try
Code:
SELECT dbo_Staff.Firstname, dbo_Staff.Surname, dbo_T_MandatoryTraining.TrainingDate, dbo_T_MandatoryTraining.CourseID
FROM dbo_Staff LEFT JOIN dbo_T_MandatoryTraining ON dbo_Staff.StaffID = dbo_T_MandatoryTraining.StaffID
and course id = 5
where dbo_T_MandatoryTraining.StaffID is null
 
How about:

Code:
SELECT dbo_Staff.Firstname, dbo_Staff.Surname
FROM dbo_Staff LEFT JOIN dbo_T_MandatoryTraining ON dbo_Staff.StaffID = dbo_T_MandatoryTraining.StaffID
WHERE dbo_T_MandatoryTraining.StaffID Is Null
 
SELECT S.Firstname, S.Surname
FROM dbo_Staff S LEFT JOIN (
SELECT StaffID FROM dbo_T_MandatoryTraining WHERE CourseID=5
) T ON S.StaffID = T.StaffID
WHERE T.StaffID Is Null

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top