• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 936
  • Last Modified:

SQL: TableA records not in TableB

(gotta love these late-afternoon brain cramps)

TableA, say 440 records, only field is ID
TableB, say 400 records, only field is ID

How to write SQL that returns the 40 TableA records that are not in TableB?  Something like...

SELECT ID
FROM TableA
LEFT JOIN TableB ON TableA.ID = TableB.ID
WHERE TableB.ID {is not in table A}

Thanks in advance.
-Jim
0
Jim Horn
Asked:
Jim Horn
  • 2
1 Solution
 
Scott PletcherSenior DBACommented:
SELECT TableA.id
FROM TableA
LEFT OUTER JOIN TableB ON TableA.id = TableB.id
WHERE TableB.id IS NULL
0
 
Scott PletcherSenior DBACommented:
SQL will automatically set every column in a not-found outer join table to NULL.
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorAuthor Commented:
ty
-Jim
0
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.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now