Finding not matching records in two tables

mrfobking

New Member
Joined
Dec 21, 2006
Messages
28
can someone help me with performing the below task? I have two tables, which can be linked with a 'ID' column. I would like to create a query that gets me the records that do NOT match.

I can find the matching records by joining the two tables, but do not know how to find the non-matching records.

Thanks in advance for your help.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Typically you perform a Left Join and filter for the NULL matches on the joined table. I think you can also use a COUNT() strategy which might be how the find unmatched records wizard works.

If you want to find non matches in both tables you have to run it twice - first the unmatched IDs in Table2 vis a vis Table1, then vice versa. You can UNION the results to form a single list of unmatched IDs (this doesn't tell you which table they are in/not in though - but you could add a Table Name as a second field.

Code:
SELECT 
	ID 
FROM 
	Table1 
	LEFT JOIN 
	Table2 
	ON Table1.ID = Table2.ID 
WHERE
	Table2.ID IS NULL
	
UNION

SELECT 
	Table2.ID 
FROM 
	Table2 
	LEFT JOIN 
	Table1 
	ON Table2.ID = Table1.ID 
WHERE
	Table1.ID IS NULL
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,728
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top