Query Question

I have the following table A, together the 2 columns make a key:

Then I have table B which is a subset of table A same columns.

How can I get the values which are in table A which are not in table B?  I need all the card/profile combinations in A which are not in B.

Who is Participating?
Sachintana DissanayakeConnect With a Mentor Senior Web DeveloperCommented:
This is more simpler using EXCEPT command which eliminates records from the second query.

(SELECT     CardNumber, Profile
FROM         TableA)
(SELECT     CardNumber, Profile
FROM         Table2)
try this
SELECT tableA.* FROM tableA LEFT JOIN tableB ON (tableA.CardNumber=tableB.CardNumber AND tableA.Profile=tableB.Profile) WHERE
(tableB.CardNumber IS NULL OR tableB.Profile IS NULL)

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.