SQL guide
Reconcile two data exports with SQL
Reconciliation goes faster when you can turn differences into a short review list. Align keys, currency precision and reporting periods before comparing systems.
Set the comparison grain
Use one row per transaction ID on both sides. If a source has multiple line items per transaction, aggregate those lines to the transaction level first.
Check both directions
Use a full outer join to include records that exist on either side. Normalize amounts to the same units and compare decimals at the desired precision.
Review and export exceptions
Check missing IDs and differing amounts with the source owners. Export the exceptions as a new file and keep the query for the next reporting period.
Example query
SELECT COALESCE(a.txn_id, b.txn_id) AS txn_id,
a.amount AS ledger_amount, b.amount AS export_amount
FROM ledger a
FULL OUTER JOIN payment_export b ON a.txn_id = b.txn_id
WHERE a.txn_id IS NULL OR b.txn_id IS NULL
OR a.amount IS DISTINCT FROM b.amount;This Standard SQL example uses synthetic table names and assumes non-null transaction IDs. Compare totals by currency independently when multiple currencies are present.