How to Merge CSV Files Without Losing Data
"Merging CSV files" actually means two different things, and picking the wrong one is the single most common way people lose or duplicate data. This guide separates the two, and covers the mistakes that cause silent data loss.
Bottom line: Combine files with identical columns by stacking rows; merge files with different columns by joining on a shared key. Most "missing rows after merging" problems come from an inner join silently dropping unmatched records.
Combining vs. Merging: Know Which One You Need
Combining (stacking rows)
Same columns, different rows, e.g. twelve monthly export files that should become one yearly file.
file1: id,name,amount
file2: id,name,amount
→ all rows appended togetherMerging (joining on a key)
Different columns, matched on a shared key, e.g. a customer list and an order list matched by customer ID.
customers: id,name
orders: customer_id,amount
→ matched by id = customer_idIf you use a row-stacking (combine) approach when you actually need a key-based join, you'll end up with a file full of unrelated columns and mostly empty cells. If you use a join when you actually need to stack, you'll lose rows that don't have a matching key on the other side.
Before You Combine: Check the Columns Match
Combining only works cleanly if every file has the same columns, in a compatible order and format. A single renamed or reordered column will misalign your data silently, watch especially for:
- Column name differences (
customer_namevscustomer namevsName) - Different column order between files
- One file with an extra or missing column
- Inconsistent date/number formats across files, even with matching column names
Choosing the Right Join Type
When merging on a key, the join type determines what happens to rows that don't have a match:
- Inner join: keeps only rows with a match in both files. Rows with no match on either side are dropped, this is the most common source of "missing data" after a merge.
- Left join: keeps every row from the first (left) file, filling in blanks where there's no match in the second file. Use this when the left file is your source of truth.
- Full/outer join: keeps every row from both files, matched where possible, blank where not. Use this when you want to see everything, including unmatched records on both sides.
Common mistake: defaulting to an inner join and not noticing that rows silently disappeared because their key didn't match exactly (extra whitespace, different capitalization, or a typo in the key column is enough to break a match).
When the Key Isn't an Exact Match
Real-world keys are messy: "Jon Smith" vs "Jonathan Smith", "123 Main St" vs "123 Main Street". A standard join requires an exact match, so these will end up unmatched. A fuzzy join, which matches on similarity rather than exact equality, is the fix, but it needs a similarity threshold you can tune, too loose and you'll merge records that shouldn't be, too strict and you'll miss real matches.
Validate After Merging
Always check row counts before and after:
- Inner join row count should be ≤ the smaller of the two input files
- Left join row count should exactly equal the left file's row count
- Full join row count should be ≥ the larger of the two input files
If the numbers don't line up with what you expect, check for duplicate keys on either side, they cause a single row to match multiple times, inflating your result.
Doing This in How To CSV
How To CSV has dedicated tools for both cases:
- Natural Join for exact-key merges with a choice of inner/left/outer join type
- Fuzzy Join for merging on approximate matches with an adjustable similarity threshold
- Smart Merge and Merge/Compare Excel Sheets for combining multiple files and reconciling differences between them
Frequently Asked Questions
What's the difference between merging and combining CSV files?
Combining stacks rows from files with the same columns (e.g. 12 monthly exports into one yearly file). Merging joins two files with different columns on a shared key (e.g. a customer list joined to an order list by customer ID).
Which join type should I use when merging CSV files?
Inner join keeps only rows matching in both files. Left join keeps every row from the first file. Full/outer join keeps every row from both. Use left or outer if you need to know about unmatched rows, inner if you only want matched pairs.
Why did rows disappear after merging two CSV files?
Almost always an inner join silently dropping rows with no matching key, or a key mismatch caused by extra whitespace, different capitalization, or a typo in the join column.
How do I merge CSV files when the key values are spelled differently?
Use a fuzzy join, which matches on similarity rather than requiring an exact match, with an adjustable threshold to control how lenient the matching is.
Ready to merge your files?
Join or combine CSV files with full control over the join type, right in your browser.
Merge Your FilesTurn this into a saved workflow
Create a free account to save the steps from this guide as a reusable workflow and re-run it on any file, from any device.