# Keep rows absent from the other table

Join / setops

A variant of [Intersect or subtract tables](https://meridian.online/operations/intersect-or-subtract-tables).

Keep the rows of the first input that do not appear in the second.

Page: <https://meridian.online/operations/intersect-or-subtract-tables/keep-rows-absent-from-the-other-table>

## Status

Runs as a SQL step.

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

## The DuckDB step

keep the rows of the first table that are absent from the second

```sql
CREATE TEMP TABLE a AS SELECT * FROM (VALUES
  (1, 'x'), (1, 'x'), (2, 'y'), (NULL, 'z'), (NULL, 'z'), (3, 'w')) t(k, v);
CREATE TEMP TABLE b AS SELECT * FROM (VALUES
  (1, 'x'), (1, 'x'), (1, 'x'), (NULL, 'z'), (2, 'y'), (4, 'u')) t(k, v);

CREATE TEMP TABLE as_set AS SELECT * FROM a EXCEPT SELECT * FROM b;
CREATE TEMP TABLE with_duplicates AS SELECT * FROM a EXCEPT ALL SELECT * FROM b;
CREATE TEMP TABLE other_way AS SELECT * FROM b EXCEPT SELECT * FROM a;
SELECT * FROM as_set ORDER BY k NULLS LAST;
SELECT * FROM with_duplicates ORDER BY k NULLS LAST;
SELECT CASE WHEN ((SELECT list((k, v) ORDER BY k) = [(3, 'w')] FROM as_set)
  AND (SELECT list((k, v) ORDER BY k NULLS LAST) IS NOT DISTINCT FROM [(3, 'w'), (NULL, 'z')] FROM with_duplicates)
  AND (SELECT list((k, v) ORDER BY k) = [(4, 'u')] FROM other_way)) THEN 'as expected' ELSE error('a EXCEPT b should leave only (3, w); with duplicates it should also leave the second (NULL, z) that b does not cover; and b EXCEPT a should leave only (4, u)') 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 DataFusion: [`EXCEPT`](https://datafusion.apache.org/user-guide/sql/select.html) (read 2026-09-27)
- Apache DataFusion: [`EXCEPT`](https://datafusion.apache.org/user-guide/sql/select.html) (read 2026-09-27)
- Apache DataFusion: [`except`](https://docs.rs/datafusion/latest/datafusion/dataframe/struct.DataFrame.html) (read 2026-09-27)
- Apache DataFusion: [`except_distinct`](https://docs.rs/datafusion/latest/datafusion/dataframe/struct.DataFrame.html) (read 2026-09-27)
- dbt-utils: [`except`](https://docs.getdbt.com/reference/dbt-jinja-functions/cross-database-macros) (read 2026-09-27)
- Duckle: [`Except / Minus`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/website/docs/components.html) (read 2026-09-25)
- Ibis: [`Difference`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/relations.py) (read 2026-09-27)
