# Compare two tables

Join / diff

compare two tables, report changed, added and removed rows

Page: <https://meridian.online/operations/compare-two-tables>

## Status

Runs as a SQL step.

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

## The DuckDB step

compare two versions of a table by key

It reads the `orders` table the proofs share. Create it first:

```sql
CREATE TABLE orders AS SELECT * FROM (VALUES
  (1,  'Alice Ng',      'north', DATE '2026-01-03', 120.00, 'widget', 'a|b',   '{"channel":"web","items":[1,2]}'),
  (2,  'alice ng',      'north', DATE '2026-01-05',  80.50, 'gadget', 'b',     '{"channel":"shop","items":[3]}'),
  (3,  'Bob  Okafor',   'south', DATE '2026-01-05', 300.00, 'widget', 'a|c',   '{"channel":"web","items":[4,5,6]}'),
  (4,  'Carla Díaz',    'east',  DATE '2026-01-09',  NULL,  'gizmo',  NULL,    '{"channel":"web","items":[]}'),
  (5,  'Bob Okafor',    'south', DATE '2026-01-12',  45.25, 'gadget', 'c',     '{"channel":"phone","items":[7]}'),
  (6,  'Dev Patel',     'west',  DATE '2026-01-12', 510.00, 'widget', 'a',     '{"channel":"web","items":[8,9]}'),
  (7,  'Carla Diaz',    'east',  DATE '2026-01-20',  99.99, 'gizmo',  'b|c',   '{"channel":"shop","items":[10]}'),
  (8,  'Dev Patel',     'west',  DATE '2026-02-02', 510.00, 'widget', 'a',     '{"channel":"web","items":[8,9]}'),
  (9,  'Eve Larsen',    NULL,    DATE '2026-02-03',  15.00, 'gadget', NULL,    '{"channel":"web","items":[11]}'),
  (10, 'Alice Ng',      'north', DATE '2026-02-10', 220.00, 'gizmo',  'a|b|c', '{"channel":"phone","items":[12,13]}')
) t(order_id, customer, region, order_date, amount, product, tags, meta);
```

Then run the statement:

```sql
CREATE TEMP TABLE result AS
WITH v2 AS (SELECT * REPLACE (CASE WHEN order_id = 3 THEN 310.0 ELSE amount END AS amount) FROM orders WHERE order_id <> 9
            UNION ALL SELECT 11, 'Gus Hale', 'north', DATE '2026-02-11', 5.0, 'gadget', NULL, '{}')
SELECT coalesce(a.order_id, b.order_id) AS order_id,
       CASE WHEN a.order_id IS NULL THEN 'added' WHEN b.order_id IS NULL THEN 'removed'
            WHEN a IS DISTINCT FROM b THEN 'changed' ELSE 'same' END AS status
FROM orders a FULL JOIN v2 b USING (order_id)
WHERE status <> 'same' ORDER BY 1;
SELECT * FROM result;
SELECT CASE WHEN ((SELECT map_from_entries(list((order_id, status) ORDER BY order_id)) = MAP {3: 'changed', 9: 'removed', 11: 'added'} FROM result)) THEN 'as expected' ELSE error('the difference is not order 3 changed, 9 removed and 11 added') END AS verdict;
```

It needs nothing installed beyond DuckDB itself.

## Variants

- [Check that two tables are identical](https://meridian.online/operations/compare-two-tables/check-that-two-tables-are-identical): Return whether two tables hold the same data.
- [Report the differences between two tables](https://meridian.online/operations/compare-two-tables/report-the-differences-between-two-tables): List where two tables differ, cell by cell, column by column or as summary statistics.
- Flag added, changed and removed rows: Match the rows of two tables on a key and tag each as unchanged, changed, added or removed.

## What other tools call it

Meridian's classification; an independent blind rating agreed on 86.2% of 312 rows (exact class, version 2).

- Bruin: [`data-diff`](https://getbruin.com/docs/bruin/commands/data-diff.html) (read 2026-09-27)
- Duckle: [`Diff Detect`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/website/docs/components.html) (read 2026-09-25)
- Duckle: [`DuckLake Data Diff`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/frontend/src/workflow-ui/palette-data.ts) (read 2026-09-25)
- Duckle: [`Reconcile (Source vs Target)`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/frontend/src/workflow-ui/palette-data.ts) (read 2026-09-25)
- EasyMorph: [`Compare tables`](https://help.easymorph.com/doku.php?id=transformations:compare) (read 2026-09-27)
- AWS Glue: [`DatasetMatch`](https://docs.aws.amazon.com/glue/latest/dg/dqdl-rule-types.html) (read 2026-09-27)
- Apache Hop: [`Merge rows (diff)`](https://hop.apache.org/manual/latest/pipeline/transforms/mergerows.html) (read 2026-09-27)
- Apache Hop: [`Table Compare`](https://hop.apache.org/manual/latest/pipeline/transforms/tablecompare.html) (read 2026-09-27)
- KNIME Analytics Platform: [`Table Difference Finder`](https://api.hub.knime.com/nodes/*36DYRFQTvb7J5vmF?details=full) (read 2026-09-27)
- Pentaho Data Integration: [`Merge Rows (diff)`](https://docs.pentaho.com/pdia-data-integration/9.3-data-integration/pdi-transformation-steps-reference-overview) (read 2026-09-27)
- Pentaho Data Integration: [`Table Compare`](https://docs.pentaho.com/pdia-data-integration/9.3-data-integration/pdi-transformation-steps-reference-overview) (read 2026-09-27)
- Polars: [`DataFrame.equals`](https://docs.pola.rs/api/python/stable/reference/dataframe/miscellaneous.html) (read 2026-09-27)
- SQLMesh: [`table_diff`](https://github.com/SQLMesh/sqlmesh/blob/23b237cea7218cc8f338b89c14f0957394a0003b/docs/guides/tablediff.md) (read 2026-09-27)
- VisiData: [`setdiff-sheet`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/experimental/diff_sheet.py#L29) (read 2026-09-23)
