Exclusion Query Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Have 2 tables, tblA, tblB. I need a query that selects all the records in
tblA that meet a set of criteria EXCEPT if there is a matching record in
tblB.

Query of tblA gives:
EntryID PenaltyID Penalty
354 7 0
638 8 0
111 5 0

Query of tblB gives:
EntryID PenaltyID Penalty
638 8 4.2

The result I need is:
EntryID PenaltyID Penalty
354 7 0
111 5 0

the record for EntryID 638 in NOT to be shown since we are looking for
entries with no penalties.

Any and all help is appreciated
 
I think this is what you want:

SELECT tblA.EntryID, tblA.PenaltyID, tblB.Penalty FROM tblA LEFT JOIN tblB
ON tblA.EntryID = tblB.EntryID AND tblA.PenaltyID = tblB.PenaltyID WHERE
tblB.Penalty IS NULL;
 
Back
Top