user3539844
user3539844

Reputation: 39

MS ACCESS Query for items not in table

I am a beginner with SQL and I have a question regarding finding a subset of data that does not exist in another table.

Currently I have 2 tables

Table A has a single column of OrderID containing about 300 records Table B also has a single column containing 1000 records

How do I write a SQL query that helps me identify the 700 records not in Table A?

Thank you

Upvotes: 0

Views: 605

Answers (2)

Raging Bull
Raging Bull

Reputation: 18747

You need to use NOT IN.Try this:

SELECT * FROM TableB
WHERE OrderID NOT IN (SELECT OrderID FROM TableA)

OR

Use a join.

SELECT B.* 
FROM TableB B LEFT JOIN TableA A ON A.OrderID = B.OrderID 
WHERE A.OrderID IS NULL

Upvotes: 1

4dmonster
4dmonster

Reputation: 3031

Try this:

SELECT TableB.* FROM TableB LEFT JOIN TableA ON TableВ.OrderID = TableA.OrderID WHERE TableA.OrderID is NULL;

Upvotes: 0

Related Questions