# Update matching rows only

Join / merge upsert

A variant of [Merge into a table](https://meridian.online/operations/merge-into-a-table).

Overwrite values in the target rows whose key matches the source, inserting nothing.

Page: <https://meridian.online/operations/merge-into-a-table/update-matching-rows-only>

## Status

Runs as a SQL step.

arcform carries it as a `sql:` step today.

## The DuckDB step

overwrite the target rows whose key matches, and insert nothing

```sql
CREATE TEMP TABLE target AS SELECT * FROM (VALUES (1, 'a', 1), (2, 'b', 2), (3, 'c', 3), (NULL, 'n', 0)) t(id, name, qty);
CREATE TEMP TABLE source AS SELECT * FROM (VALUES
  (1, 'A', 10, 1), (2, 'b1', 20, 1), (2, 'b2', 21, 2), (3, NULL, NULL, 1), (9, 'new', 9, 1), (NULL, 'nk', 5, 1)) t(id, name, qty, seq);
-- MERGE stops if one target row matches two source rows, so the source keeps its latest row for each key (the NULL key matches no target row)
MERGE INTO target t USING (SELECT id, name, qty FROM source QUALIFY row_number() OVER (PARTITION BY id ORDER BY seq DESC) = 1) s ON t.id = s.id
  WHEN MATCHED THEN UPDATE SET name = s.name, qty = s.qty;
SELECT * FROM target ORDER BY id NULLS LAST;
SELECT CASE WHEN ((SELECT count(*) = 4 AND list((id, name, qty) ORDER BY id NULLS LAST) IS NOT DISTINCT FROM [(1, 'A', 10), (2, 'b2', 21), (3, NULL, NULL), (NULL, 'n', 0)] FROM target)) THEN 'as expected' ELSE error('the target should still hold 4 rows: ids 1 and 2 overwritten (2 by its latest source row), id 3 overwritten with NULLs, the NULL-key row untouched and no row for the unmatched keys 9 and NULL') END AS verdict;
```

The statement builds its own data.

It needs nothing installed beyond DuckDB itself.

## What other tools call it

Meridian's classification; an independent blind rating agreed on 95.7% of 324 rows (variant, version 3).

- Apache Hop: [`Update`](https://hop.apache.org/manual/latest/pipeline/transforms/update.html) (read 2026-09-27)
- KNIME Analytics Platform: [`Table Updater`](https://api.hub.knime.com/nodes/*6MrPSJf3gPseMOiy?details=full) (read 2026-09-27)
- Pentaho Data Integration: [`Update`](https://docs.pentaho.com/pdia-data-integration/9.3-data-integration/pdi-transformation-steps-reference-overview) (read 2026-09-27)
- Polars: [`DataFrame.update`](https://docs.pola.rs/api/python/stable/reference/dataframe/modify_select.html) (read 2026-09-27)
- RapidMiner Studio: [`Update Database`](https://docs.rapidminer.com/latest/studio/operators/data_access/database/update_database.html) (read 2026-09-27)
- RapidMiner Studio: [`Update MongoDB`](https://docs.rapidminer.com/latest/studio/operators/data_access/nosql/mongodb/mongodb_document_updater.html) (read 2026-09-27)
