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

SQL: Select rows that are not present in table 2

Status
Not open for further replies.

mkingrey

Programmer
Apr 12, 2006
5
US
I have Table1 with FieldA and Table2 with FieldA. I would like to query Table1 for all records that DO NOT exist in FieldA of Table2. I have tried the following but it doesn't filter correctly. Any suggestions?? Thx!!

SELECT Table1.FieldA FROM Table1, Table2 WHERE Table1.FieldA <> Table2.Field
 
SELECT Table1.FieldA
FROM Table1 LEFT OUTER JOIN Table2
ON Table1.FieldA = Table2.Field
WHERE Table2.Field is null

r937.com | rudy.ca
 
either:
SELECT * FROM Table1
WHERE FieldA NOT IN (SELECT FieldA FROM Table2)

or:
SELECT A.*
FROM Table1 A LEFT JOIN Table2 B ON A.FieldA = B.FieldA
WHERE B.FieldA IS NULL

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top