How can I get the missing records from 2 tables

Viewed 31

Due to an error in our application, a process which normally inserts data to 2 tables, intermittently only updated one table. I need to identify all records where the record was added to Table_A but not added to Table_B. A simplified example of my schema is:

Table_A
Table_A_Id
ClientId
DateAdded
Table_B
Table_B_Id
ClientId
Category
DateAdded

Both Table_A and Table_B can have multiple duplicate ClientIds so I need to find records where ClientId was added to Table_A on a specific date but Table_B does not have that ClientId with the matching DateAdded record. Can anyone help with some SQL that could identify these missing records?

1 Answers

You could use the EXCEPT clause to locate the missing data. This will return rows found in Table_A only.

select ClientId, DateAdded
from Table_A
except
select ClientID, DateAdded
from Table_B
Related