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

Check if data in one table field located in another table field 1

Status
Not open for further replies.

DIVINEDAR0956

IS-IT--Management
Aug 15, 2002
95
0
0
US
Can someone help me figure out how to check one table against another. If I have a value in one primary key field in TBL1, how can I check that value against TBL2?

Please help!!!

Thank you. Darlene Sippio
dsippio@comtechsystems.com
 
SELECT TBL1.*, TBL2.*
FROM TBL1 LEFT JOIN TBL2
ON TBL1.KeyField = TBL2.KeyField
WHERE TBL2.KeyField Is Null

Replace KeyField with your column name.

The LEFT JOIN includes all records from TBL1, and joins all records from TBL2 that have a match, leaving those w/o a match with null values in the TBL2 columns. The WHERE clause then takes out the rows that successfully joined.

Viewing the returned recordset without the Where clause may be more helpful in trying to understand how the tables join.

You may want to try this, as well:

SELECT TBL1.*, TBL2.*
FROM TBL2 LEFT JOIN TBL1
ON TBL2.KeyField = TBL1.KeyField
WHERE TBL1.KeyField Is Null

PS You can enforce referencial integrity among tables by creating relationships under Tools|Relationships.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top