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

Comparing 1 field from 2 tables and list values not found in both 2

Status
Not open for further replies.

robojeff

Technical User
Joined
Dec 5, 2008
Messages
220
Location
US
I need a way to look at one field from two different tables and create a list of any items which are not in both tables but I am not sure how to do this...

Can this be done with a query?

 
SELECT Table1.yourField AS Item, 'Table1 only' AS Location
FROM Table1 LEFT JOIN Table2 ON Table1.yourField=Table2.yourField
WHERE Table2.yourField Is Null
UNION SELECT Table2.yourField, 'Table2 only'
FROM Table1 RIGHT JOIN Table2 ON Table1.yourField=Table2.yourField
WHERE Table1.yourField Is Null

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The above alone is worth hanging out in this forum. I've wanted to know how to answer the question "show me what isn't on both lists" for a long time and never did figure it out.

Worth the price of admission. LOL.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top