# CSV left join

`csv-left-join` · version 1.0.0 · CSV & tables · free, no key needed

Left join two CSV documents on exact named key columns.

**Use when you need to: csv left join · left join csv documents · left join csv on named keys.**

## Supported

- csv left join
- left join csv documents
- left join csv on named keys

## Not supported

- inner join
- right join
- full outer join
- fuzzy keys
- numeric keys
- read files
- fetch urls

## Behavior

- left and right are complete CSV documents whose first records are headers.
- keys names unique headers present in both documents; join uses exact string tuples with no coercion.
- Output columns are the keys in listed order, then remaining left columns in left header order, then remaining right columns in right header order.
- Non-key header collisions are renamed with left_suffix and right_suffix (defaults _left and _right); remaining collisions throw.
- Every left data row appears; matching is a cartesian product of right rows with the same key, in left then right order.
- Left rows with no match emit empty strings for right-only columns; unmatched_left_rows counts those left rows.
- Empty documents without headers are rejected; header-only inputs yield the computed header and zero data rows.
- A join key may not appear on more than 64 data rows on either side.
- The first output header name may not begin with U+FEFF because it is ambiguous with a CSV byte-order mark.

## Input

- `left` (string, required): max length 256000
- `right` (string, required): max length 256000
- `keys` (array of string, required): min items 1; max items 32; each min length 1
- `left_suffix` (string, optional): min length 1; max length 32; default `"_left"`
- `right_suffix` (string, optional): min length 1; max length 32; default `"_right"`

## Output

- `csv` (string, required)
- `rows_out` (integer, required)
- `unmatched_left_rows` (integer, required)

## Limits

- max input bytes: 256000
- max data rows: 5000
- max columns: 256
- max header name bytes: 256
- max keys: 32
- max suffix chars: 32
- max duplicate rows per key: 64
- max output bytes: 256000

## Example

Request input:

```json
{
  "left": "id,name\n1,Ada\n2,Lin\n3,Grace\n",
  "right": "id,city\n1,London\n1,Paris\n4,Tokyo\n",
  "keys": [
    "id"
  ]
}
```

Response:

```json
{
  "result": {
    "csv": "id,name,city\n1,Ada,London\n1,Ada,Paris\n2,Lin,\n3,Grace,\n",
    "rows_out": 4,
    "unmatched_left_rows": 2
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "csv-left-join",
  "version": "1.0.0",
  "input": {
    "left": "id,name\n1,Ada\n2,Lin\n3,Grace\n",
    "right": "id,city\n1,London\n1,Paris\n4,Tokyo\n",
    "keys": [
      "id"
    ]
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/csv-left-join/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"left":"id,name\n1,Ada\n2,Lin\n3,Grace\n","right":"id,city\n1,London\n1,Paris\n4,Tokyo\n","keys":["id"]}'
```

The machine-readable contract is at [/v1/tools/csv-left-join/versions/1.0.0](/v1/tools/csv-left-join/versions/1.0.0).

### CLI

```sh
node cli.mjs run csv-left-join 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [CSV inner join](/tools/csv-inner-join): Inner join two CSV documents on exact named key columns.
- [CSV anti join](/tools/csv-anti-join): Keep left CSV rows whose exact key tuples do not appear in the right document.
- [CSV concat](/tools/csv-concat): Concatenate CSV documents that share identical headers, preserving document and row order.
- [CSV dedupe](/tools/csv-dedupe): Remove duplicate CSV data rows while preserving the first occurrence.
- [CSV merge columns](/tools/csv-merge-columns): Join named CSV columns with an exact separator into one column.
- [CSV reconcile](/tools/csv-reconcile): Reconcile two CSV documents by key columns, reporting full population totals and bounded samples for added, removed, changed, invalid-key, and ambiguous rows.
