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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Querry

Status
Not open for further replies.

mevasquez

Programmer
Aug 26, 2003
75
US
I have three tables, personnel, qualification, qualifications.

The personnel table list fname,lname and other information about the person
The qualification table list all the different qualifications/training, i.e. Annual Safty Training, Divisional Coordinator, Tow Tractor, etc.
The qualifications table maintains all personnel and their qualifications. Smith, Tow Tractor; Taylor, Tow Tractor; Jones, Annual Safty Training, etc.

What I am trying to do is find all the people who are not qualified for a particular qualification.
If I choose Annual Safty Training, the result set should be, Smith and Taylor.
If I choose Divisional Coordinator, the result set should be Smith, Taylor and Jones, etc.
If I choose Tow Tractor, the result set should be Jones.

The Primary Key for Personnel is pid
The Primary Key for Qualification is qid
The Qualifications table has FK to Personnel and the Qualification table

Any help would be appreciated.

Thanks,

Mike
 
Code:
SELECT *
FROM Personnel
WHERE pid NOT IN (
      SELECT pid FROM Qualifications 
      WHERE qid = @target_qualification_id
     )

Everyone qualified on @target_qualification_id is in the subquery; the outer query gives everyone else.
 
Thanks, that was it. Looks like I will have to read up on the NOT IN statement. Never used it before.

Thanks again,

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top