How to Merge Two CSV Files
Combine two CSV files into one, whether you're stacking rows or joining columns on a shared key.
Merging CSVs means one of two very different things, and confusing them is the usual source of broken output. Stacking (appending) puts the rows of one file after the other, which works when both files share the same columns. Joining matches rows across files on a shared key and combines their columns, which is what you want when each file holds different fields about the same records.
Decide which you need before you start. If the files have the same headers and you just want more rows, you're stacking. If you want to enrich one dataset with columns from another (say orders plus customer details, keyed by customer ID), you're joining.
- 1
Confirm the two files' structure
For a stack, both files need the same columns with the same meaning. For a join, identify the key column present in both (an ID or email).
- 2
Stack rows (same columns)
Append the second file's data rows beneath the first, keeping a single header. A converter or a quick copy-paste handles this; then dedupe if the files overlap.
- 3
Join on a key (different columns)
Use a spreadsheet's XLOOKUP or a database to pull columns from one file into the other, matching on the shared key. Validate that every key matched.
- 4
Check for duplicates and gaps
After merging, remove duplicate rows introduced by overlap, and confirm no rows lost their key match.
Frequently asked questions
Stacking vs joining, which do I need?▾
Stack when the files have the same columns and you want more rows. Join when the files have different columns about the same records and you want to combine fields on a shared key.
How do I avoid duplicate rows after stacking?▾
Run a deduplication pass keyed on the column (or columns) that uniquely identify a record, not on the entire row, since formatting can differ.
What if the headers don't match exactly?▾
Standardize the headers first. Stacking and joining both rely on consistent column names; a trailing space or different capitalization breaks the alignment.