CSV Join by Key
Combine two CSV files using a matching column
CSV Join by Key — what it does
Combine two CSV files on a matching column using an inner, left or full join. Each row from the first file is paired with rows from the second where the key values agree, giving you the equivalent of a database join or a VLOOKUP across an entire file, without writing a formula per row.
Worked example
An employee list joined to a department list on dept_id with a Left join, so an employee whose department code is missing from the lookup file is kept with blank department fields.
Input — employees.csv and departments.csv
employees.csv emp_id,name,dept_id E-01,Ann Lee,D10 E-02,Ben Ortiz,D20 E-03,Chloe Park,D10 E-04,Emma Rossi,D40 departments.csv dept_id,dept_name,location D10,Sales,London D20,Engineering,Berlin D30,Support,Dublin
Output — joined.csv (Left join)
emp_id,name,dept_id,dept_name,location E-01,Ann Lee,D10,Sales,London E-02,Ben Ortiz,D20,Engineering,Berlin E-03,Chloe Park,D10,Sales,London E-04,Emma Rossi,D40,,
The second file's key column is dropped, so dept_id appears once, and the status reads 4 joined rows. Switching to Full join adds a fifth row for the unmatched department: ,,D30,Support,Dublin. The download is always joined.csv.
When this tool helps
- Enriching an order export with customer details held in a separate contacts file.
- Attaching product names and prices to a transaction log that only carries SKU codes.
- Finding records present in one system but missing from another by inspecting a full join's blanks.
How to use it
- Load the first CSV and the second CSV.
- Select the key column in each file.
- Choose inner, left or full join.
- Process and download the joined result.
Accuracy, limits, and good practice
- Inner keeps only matched rows, left keeps every row from the first file, and full keeps everything from both — the choice decides what silently disappears.
- If the key repeats in the second file, matching rows multiply. Deduplicate the lookup side first unless you intend a one-to-many expansion.
- Keys must match exactly, so leading zeros stripped by a spreadsheet are a frequent cause of joins that return nothing.
Frequently asked questions
Which join should I use by default?
Left join. It keeps your primary dataset intact and shows blanks where the lookup file had no match, which is usually what you want to see.
What if column names collide?
Both are carried into the output, so rename one side first with the column renamer to keep the result readable.
Can the key columns have different names?
Yes. You select the key in each file independently, so id and customer_id can be matched without renaming anything.
How does a Full join show a row that exists only in the second file?
It is appended after the first file's rows with every first-file column empty except the key, which is filled with the second file's key value — ,,D30,Support,Dublin in the example above.
Is the key match case-sensitive?
Yes. Keys are compared as exact strings, so D10 and d10 do not match, and neither do D10 and 'D10 ' with a trailing space. Trim and normalise both key columns before joining.
Related tools on this site
- CSV Transposer — Swap CSV rows and columns and download the result
- JSON Merge Tool — Merge two JSON objects or arrays with multiple strategies
- CSV Column Statistics — Calculate numeric and uniqueness statistics for one column
Further reading: Cleaning a CSV export before you import it anywhere · CSV, JSON, YAML, XML and Markdown Tables: When Each Fits and How to Convert
Everything above runs inside this page. CSV Join by Key needs no account, no upload, and no server round trip — close the tab and nothing is left behind.
CSV 欄位關聯合併能做什麼
以相符欄位用內部、左側或完整合併把兩份 CSV 結合起來。第一份檔案的每一列,會與第二份中鍵值相符的列配對,效果等同資料庫的 JOIN 或整檔套用 VLOOKUP,而不必逐列寫公式。
實際範例
員工名單以 dept_id 關聯部門清單,選左外部合併,部門代碼在對照檔裡找不到的員工也會留下,部門欄位留白。
來源:employees.csv 與 departments.csv
employees.csv emp_id,name,dept_id E-01,Ann Lee,D10 E-02,Ben Ortiz,D20 E-03,Chloe Park,D10 E-04,Emma Rossi,D40 departments.csv dept_id,dept_name,location D10,Sales,London D20,Engineering,Berlin D30,Support,Dublin
得到:joined.csv(左外部合併)
emp_id,name,dept_id,dept_name,location E-01,Ann Lee,D10,Sales,London E-02,Ben Ortiz,D20,Engineering,Berlin E-03,Chloe Park,D10,Sales,London E-04,Emma Rossi,D40,,
第二個檔案的鍵欄位會被拿掉,所以 dept_id 只有一欄;狀態列顯示 4 joined rows。改成完全合併會多一列沒配到的部門:,,D30,Support,Dublin。下載檔一律叫 joined.csv。
什麼時候用得上
- 把另一份聯絡人檔案中的客戶資料,補進訂單匯出檔。
- 為只有 SKU 代碼的交易紀錄,補上商品名稱與價格。
- 透過完整合併中的空白欄,找出只存在於某一個系統的紀錄。
使用步驟
- 載入第一份與第二份 CSV。
- 分別選定兩邊的鍵值欄位。
- 選擇內部、左側或完整合併。
- 執行處理並下載合併結果。
精確度、限制與實務建議
- 內部合併只留配對成功的列,左側合併保留第一份的所有列,完整合併兩邊都留——這個選擇決定了什麼會悄悄消失。
- 若鍵值在第二份檔案中重複,配對結果會倍增。除非刻意要一對多展開,否則請先對查表側去重。
- 鍵值必須完全相符,被試算表吃掉前置零是合併結果全空最常見的原因。
常見問題
預設該用哪種合併?
左側合併。它保留主要資料集的完整性,並在查不到對應時留白,通常正是你想看到的樣子。
欄位名稱重複怎麼辦?
兩邊都會寫進輸出,建議先用欄位改名工具把其中一邊改掉,結果才好讀。
兩邊鍵值欄位名稱不同可以嗎?
可以。兩份檔案各自選定鍵值欄位,因此 id 與 customer_id 不必改名就能配對。
完全合併時,只在第二個檔案裡的列會長什麼樣?
它會被接在第一個檔案的列後面,第一個檔案的欄位全部留空、只有鍵欄位填上第二個檔案的鍵值,就是上面例子裡的 ,,D30,Support,Dublin。
鍵的比對區分大小寫嗎?
區分。鍵以完全相同的字串比對,D10 與 d10 配不上,D10 與尾端多一個空格的「D10 」也配不上。合併前請先把兩邊的鍵欄位去掉空白並統一寫法。
本站相關工具
延伸閱讀: 匯入之前先把 CSV 匯出檔清乾淨 · CSV、JSON、YAML、XML 與 Markdown 表格:各自適用的場合與轉換方法
以上步驟全部在這個頁面內完成,CSV 欄位關聯合併 不需要註冊、不上傳檔案、也不經過伺服器,關閉分頁後不會留下任何資料。