How to compare two CSV files by ID instead of row order
Last reviewed: . Two exports can contain the same records in different orders. A line-by-line comparison will report many apparent changes even when only one value actually changed. Match each record by a stable ID to find the differences that matter.
This walkthrough uses FilePebble's CSV comparison tool, which processes the CSV text in your browser and can export a JSON report. You can follow the method with other CSV comparison software too.
1. Start with two small exports
Imagine comparing yesterday's customer export against today's. The updated export has been sorted differently, one city was corrected, one customer disappeared and one was added.
Original CSV
id,name,city,plan
001,Asha,Mangaluru,basic
002,Ravi,Udupi,pro
003,Maya,Karwar,basicUpdated CSV
id,name,city,plan
002,Ravi,Manipal,pro
001,Asha,Mangaluru,basic
004,Neha,Goa,basicNotice that 001 has moved from the first data row to the second. That move should not count as a changed customer. Also notice that 001 includes leading zeros; exporting or opening the CSV through a spreadsheet can accidentally remove them if the ID column is interpreted as a number.
2. Choose a unique key column
Open Compare CSV files. Paste the original text on the left and the updated text on the right, or open the two local CSV files. In the Key column input, enter id and select Compare CSV.
A useful key appears in both files and identifies one record uniquely within each file. An internal customer ID or invoice ID is usually more reliable than a person's name. The current FilePebble tool requires non-empty, unique key values and matches keys exactly, including case and whitespace.
If you leave the key input blank, FilePebble compares data rows by position. That is useful when row position itself is meaningful, but it is misleading for exports that reorder the same records.
3. Understand the actual differences
With id selected, the example contains one changed record, one removed record, one added record and one unchanged record.
- Changed: ID
002changes its city fromUdupitoManipal. - Removed: ID
003exists only in the original export. - Added: ID
004exists only in the updated export. - Unchanged: ID
001has identical values despite moving to another row.
The on-screen preview shows a limited number of changed rows for readability. Use Download result to retain the complete JSON report. It is a report of differences, not a merged or corrected CSV.
4. Avoid the most common CSV comparison mistakes
- Duplicate keys: Two records with the same ID make it ambiguous which records should match. Fix the source export or choose a genuinely unique field.
- Missing keys: A blank ID will be rejected in key-matching mode. Do not silently invent IDs just to make the comparison run.
- Changed formatting:
001and1are different keys. Import ID columns as text when working in Excel or similar software. - Moved columns: FilePebble matches fields by header name, so changing the order of columns does not by itself imply changed cells. Added and removed columns are reported separately.
- Quoted commas: A cell such as
"Mangaluru, Karnataka"must be quoted in a CSV export. Otherwise the comma can be read as a column separator. - Whitespace and case: Optional settings can ignore edge whitespace or letter case in compared cell values; they do not change how keys match.
5. Check the report before acting on it
A changed row is a signal to investigate, not automatic proof of a data error. For example, a city correction may be intended, while a removed record could be due to a filter in the second export. Review how each file was produced and whether it covers the same time period and columns.
If you plan to share a report containing customer information, review what it includes first. FilePebble runs the comparison locally in your browser, but the downloaded JSON file still contains values from your inputs and should be handled appropriately.
What the tool does not do
The CSV comparison tool does not read Excel .xlsx workbooks, infer a key automatically, perform a database join, or reconcile conflicting records. Export a real CSV or TSV first. Current limits are 1 MB, 10,000 data rows and 100 columns per input; the screen shows up to 200 changed rows, while the JSON report contains the full comparison within supported limits.
Try it with your exports
Open FilePebble's CSV comparison tool and use the sample rows above to confirm the result before trying your own files. For format changes rather than comparing exports, see CSV to JSON or JSON to CSV.
Put it into practice
Try the steps with a small sample before processing important files. Keep an original copy and review exported results.