Not Trained Query (1 Viewer)

Waddy

Registered User.
Local time
Today, 20:22
Joined
Nov 26, 2018
Messages
32
Hi All,

I have a query that shows what training an employee has, how would I go about showing what training he/she does not have in a query.

(Indicates Primary Key On Each Table)

I have a list of training courses in a table called tblCourses (CourseID)
I have a table called employees called tblEmployees (OracleNo)
And I have a table were the information is stored called tblTraining (OracleNo)

On a query I just used the tblTraining to get what he/she is trained in but how would I approach not trained in.

I hope you can help, like you always have :)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:22
Joined
May 7, 2009
Messages
19,231
to show a list that courses that an employee has not taken:

select tblcourse.courseid from tblcourse where tblcourse.courseid not in (select tblemployee.courseid from tblemployee where tblemployee.empid="theEmployeeIDhere");
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:22
Joined
Feb 19, 2002
Messages
43,213
When you don't know how to build a query, the QBE can be very helpful. This is a typical find unmatched query. Try running the wizard and see if that gets what you want. Then switch the query to SQL View to examine the generated SQL string. You will find that it joins the tables with a left join and looks for training where the courseID is null (i.e. not found).
 

plog

Banishment Pending
Local time
Today, 14:22
Joined
May 11, 2011
Messages
11,638
First, you need a list of every Course/Employee permutation. THis query will do that:

Code:
SELECT CourseID, OracleNo
FROM tblCourses, tblEmployees

Paste that SQL into a new query and call it 'sub_MissingTraining'. Then, from that subtract out all Course/Employees in tblTraining and you will get your required data. This subtraction can be achieved with a LEFT JOIN (showing all from sub_MissingTraining) and applying Null criteria on tblTraining. This is that SQL:

Code:
SELECT sub_MissingTraining.CourseID, sub_MissingTraining.OracleNo
FROM sub_MissingTraining
LEFT JOIN tblTraining ON sub_MissingTraning.CourseID = tblTraining.CourseID
  AND sub_MissingTraning.OracleNo = tblTraining.OracleNo
WHERE tblTraining.OracleNo IS NULL
 

Users who are viewing this thread

Top Bottom