You have two exports. One is the source of truth (every paying customer in billing), the other is what you're auditing (customers synced to the CRM). The question is always the same: which IDs are in the first list but missing from the second?
Here are three ways to answer it, depending on where the data lives.
1. Both lists are already in the database
Use an anti-join. NOT EXISTS is the safe default because it behaves correctly when the other side contains NULL s ( NOT IN does not):
SELECT b . customer_id FROM billing b WHERE NOT EXISTS ( SELECT 1 FROM crm c WHERE c . customer_id = b . customer_id );
Enter fullscreen mode
Exit fullscreen mode
Or, if your database supports it:
SELECT customer_id FROM billing EXCEPT SELECT customer_id FROM crm ;
Enter fullscreen mode
Exit fullscreen mode
2. One list is in a spreadsheet, the other in the database
Turn the pasted list into rows with VALUES , then anti-join against the table:
SELECT v .…