# Look up values from a reference table

Join / lookup

enrich from a reference table

Page: <https://meridian.online/operations/look-up-values-from-a-reference-table>

## Status

Runs as a SQL step.

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

## The DuckDB step

enrich with a default when the key is missing

It reads the `orders` and `customers` tables the proofs share. Create them 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);

CREATE TABLE customers AS SELECT * FROM (VALUES
  ('Alice Ng',    'retail',    DATE '2025-06-01', 52.52, 13.40),
  ('Bob Okafor',  'wholesale', DATE '2025-09-15', 48.85,  2.35),
  ('Carla Diaz',  'retail',    DATE '2025-11-30', 40.42, -3.70),
  ('Frank Moore', 'retail',    DATE '2026-01-01', 51.51, -0.13)
) t(customer, segment, joined, lat, lon);
```

Then run the statement:

```sql
CREATE TEMP TABLE result AS
SELECT o.order_id, o.customer, coalesce(c.segment, 'unassigned') AS segment FROM orders o LEFT JOIN customers c USING (customer);
SELECT * FROM result;
SELECT CASE WHEN ((SELECT count(*) = 10 AND count(*) FILTER (WHERE segment = 'unassigned') = 6 AND max(segment) FILTER (WHERE order_id = 6) = 'unassigned' FROM result)) THEN 'as expected' ELSE error('an order with no match did not take the default') END AS verdict;
```

It needs nothing installed beyond DuckDB itself.

## Variants

- Add columns from a reference table by key: Match each row to a reference table on a key and append the matching row's columns, keeping every input row.
- [Look up with a query for each row](https://meridian.online/operations/look-up-values-from-a-reference-table/look-up-with-a-query-for-each-row): Run a subquery or parameterised query for each input row and attach what it returns.
- Append data from a reference service: Add columns from a vendor dataset, reconciliation service or reference index matched to each row.
- Replace text using a dictionary table: Find text from a second table in each value and replace it with that table's entry.

## What other tools call it

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

- Azure Data Factory: [`Cached lookup functions`](https://learn.microsoft.com/en-us/azure/data-factory/data-flow-cached-lookup-functions) (read 2026-09-27)
- Azure Data Factory: [`Lookup`](https://learn.microsoft.com/en-us/azure/data-factory/data-flow-lookup) (read 2026-09-27)
- Alteryx Designer: [`Allocate Append`](https://help.alteryx.com/current/en/designer/tools/demographic-analysis/allocate-append-tool.html) (read 2026-09-27)
- Alteryx Designer: [`Calgary Cross Count Append`](https://help.alteryx.com/current/en/designer/tools/calgary/calgary-cross-count-append-tool.html) (read 2026-09-27)
- Alteryx Designer: [`Cluster Code`](https://help.alteryx.com/current/en/designer/tools/behavior-analysis/cluster-code-tool.html) (read 2026-09-27)
- Alteryx Designer: [`Find Replace`](https://help.alteryx.com/current/en/designer/tools/join/find-replace-tool.html) (read 2026-09-27)
- Alteryx Designer: [`Marketo Append`](https://help.alteryx.com/current/en/designer/tools/connectors/marketo-append-tool.html) (read 2026-09-27)
- Apache DataFusion: [`Correlated subqueries`](https://datafusion.apache.org/user-guide/sql/subqueries.html) (read 2026-09-27)
- Apache DataFusion: [`LATERAL JOIN`](https://datafusion.apache.org/user-guide/sql/select.html) (read 2026-09-27)
- Apache DataFusion: [`Scalar subqueries`](https://datafusion.apache.org/user-guide/sql/subqueries.html) (read 2026-09-27)
- Duckle: [`Lookup`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/website/docs/components.html) (read 2026-09-25)
- Duckle: [`Map`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/website/docs/components.html) (read 2026-09-25)
- EasyMorph: [`Lookup`](https://help.easymorph.com/doku.php?id=transformations:lookup) (read 2026-09-27)
- EasyMorph: [`Match`](https://help.easymorph.com/doku.php?id=transformations:match) (read 2026-09-27)
- AWS Glue: [`Lookup`](https://docs.aws.amazon.com/glue/latest/dg/transforms-lookup.html) (read 2026-09-27)
- Apache Hop: [`Database Join`](https://hop.apache.org/manual/latest/pipeline/transforms/databasejoin.html) (read 2026-09-27)
- Apache Hop: [`Database Lookup`](https://hop.apache.org/manual/latest/pipeline/transforms/databaselookup.html) (read 2026-09-27)
- Apache Hop: [`Dynamic SQL row`](https://hop.apache.org/manual/latest/pipeline/transforms/dynamicsqlrow.html) (read 2026-09-27)
- Apache Hop: [`Stream Lookup`](https://hop.apache.org/manual/latest/pipeline/transforms/streamlookup.html) (read 2026-09-27)
- KNIME Analytics Platform: [`Value Lookup`](https://api.hub.knime.com/nodes/*S2w-f2z3562iiLac?details=full) (read 2026-09-27)
- Apache NiFi: [`FetchDistributedMapCache`](https://nifi.apache.org/components/org.apache.nifi.processors.standard.FetchDistributedMapCache/) (read 2026-09-27)
- Apache NiFi: [`ISPEnrichIP`](https://nifi.apache.org/components/org.apache.nifi.processors.ISPEnrichIP/) (read 2026-09-27)
- Apache NiFi: [`JoinEnrichment`](https://nifi.apache.org/components/org.apache.nifi.processors.standard.JoinEnrichment/) (read 2026-09-27)
- Apache NiFi: [`Lookup services (family)`](https://nifi.apache.org/components/) (read 2026-09-27)
- Apache NiFi: [`LookupAttribute`](https://nifi.apache.org/components/org.apache.nifi.processors.standard.LookupAttribute/) (read 2026-09-27)
- Apache NiFi: [`LookupRecord`](https://nifi.apache.org/components/org.apache.nifi.processors.standard.LookupRecord/) (read 2026-09-27)
- OpenRefine: [`Add columns from reconciled values…`](https://openrefine.org/docs/manual/reconciling#add-columns-from-reconciled-values) (read 2026-09-27)
- OpenRefine: [`cross(cell, s projectName (optional), s columnName (optional))`](https://openrefine.org/docs/manual/grelfunctions#other-functions) (read 2026-09-27)
- Pentaho Data Integration: [`Database join`](https://docs.pentaho.com/pdia-data-integration/9.3-data-integration/pdi-transformation-steps-reference-overview) (read 2026-09-27)
- Pentaho Data Integration: [`Database lookup`](https://docs.pentaho.com/pdia-data-integration/9.3-data-integration/pdi-transformation-steps-reference-overview) (read 2026-09-27)
- Pentaho Data Integration: [`Dynamic SQL row`](https://docs.pentaho.com/pdia-data-integration/9.3-data-integration/pdi-transformation-steps-reference-overview) (read 2026-09-27)
- Pentaho Data Integration: [`Stream lookup`](https://docs.pentaho.com/pdia-data-integration/9.3-data-integration/pdi-transformation-steps-reference-overview) (read 2026-09-27)
- RapidMiner Studio: [`Replace (Dictionary)`](https://docs.rapidminer.com/latest/studio/operators/blending/values/replace_dictionary.html) (read 2026-09-27)
- Talend: [`tFirstnameMatch`](https://help.qlik.com/talend/en-US/components/8.0/name-standardization/name-standardization-component) (read 2026-09-27)
- Talend: [`tSynonymSearch`](https://help.qlik.com/talend/en-US/components/8.0/synonym-index/synonym-index-component) (read 2026-09-27)
- VisiData: [`join-cols-extend`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/join.py#L423) (read 2026-09-23)
- VisiData: [`join-selected-extend`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/join.py#L420) (read 2026-09-23)
- VisiData: [`join-sheets-all-extend`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/join.py#L422) (read 2026-09-23)
- VisiData: [`join-sheets-top2-extend`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/join.py#L421) (read 2026-09-23)
