Join CSV files
By Tanin Na Nakorn · Updated
There are two different things people mean by "joining" CSV files. Superintendent does both with SQL:
- Join: put columns side by side, matching rows on a key. Orders plus customer details.
- Append: stack rows from files that have the same columns. Twelve monthly exports into one year.
Import the files
Drop the CSV files onto Superintendent, or use Import CSV. Each file becomes a table named after
it. Column names are cleaned up on import, so Customer ID in one file and Customer_ID in
another both end up as Customer_ID.
Join two CSV files on a column
Say orders.csv has one row per order with a customer_id, and customers.csv
has one row per customer. To add each customer's name and country to their orders:
select
o.order_id,
o.ordered_at,
o.amount,
c.name,
c.country
from orders o
left join customers c on c.customer_id = o.customer_id
| order_id | ordered_at | amount | name | country | |
|---|---|---|---|---|---|
| 1 | A-100231 | 2025-03-01 09:14:02 | 129.00 | Stone Learning | US |
| 2 | A-100232 | 2025-03-01 09:15:40 | 49.00 | Copper Health | CA |
| 3 | A-100233 | 2025-03-01 09:21:11 | 499.00 | NULL | NULL |
A left join keeps every order, even ones without a matching customer (the last row above). Use
join instead to keep only the orders that match.
Find the rows that didn't match
Rows that don't match are usually the interesting part: a typo in an ID, a customer missing from the export, a leading zero that got dropped. To list them:
select o.*
from orders o
left join customers c on c.customer_id = o.customer_id
where c.customer_id is null
Join on more than one column, or on messy values
Join on several columns with and. When the values don't match exactly, clean them up in the join
itself:
select *
from signups s
join invoices i
on lower(trim(i.email)) = lower(trim(s.email))
and i.country = s.country
Append CSV files with the same columns
To stack monthly exports into one table, use union all:
select * from orders_2025_01
union all
select * from orders_2025_02
union all
select * from orders_2025_03
If the files have the same columns in a different order, use union all by name, which matches columns
by name instead of position.
Save the result
Click Export CSV to save the joined result as a new file. Or keep working on it: the query result shows up as a table you can query again. To join a CSV with live database data, see Reconcile a Stripe CSV export with Postgres.
Questions
How is this different from VLOOKUP?
A join does what VLOOKUP does, but for every column at once, on files of any size, without copying formulas down a million rows. It also shows you the rows that didn't match.
Can I join more than two CSV files?
Yes. Import as many files as you need and add another join for each one.
Can I join a CSV with a database table?
Yes. Connect to PostgreSQL, SQLite, ClickHouse, or Snowflake, download a table or query result into the workspace, and join it with the CSV like any other table.
How do I save the joined result as a CSV?
Click Export CSV above the result grid, choose the delimiter, and save the file.