# Find items that occur together

Model / associate

association rules, frequent itemsets, market basket

Page: <https://meridian.online/operations/find-items-that-occur-together>

## Status

Runs as a SQL step.

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

## The DuckDB step

pairs of products bought by the same customer

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 basket AS (SELECT DISTINCT lower(strip_accents(regexp_replace(customer, '\s+', ' ', 'g'))) AS who, product FROM orders)
SELECT a.product AS p1, b.product AS p2, count(*) AS together
FROM basket a JOIN basket b ON a.who = b.who AND a.product < b.product GROUP BY ALL ORDER BY together DESC;
SELECT * FROM result ORDER BY together DESC, p1, p2;
SELECT CASE WHEN ((SELECT list(p1 || '+' || p2 || '=' || together ORDER BY p1, p2) = ['gadget+gizmo=1', 'gadget+widget=2', 'gizmo+widget=1'] FROM result)) THEN 'as expected' ELSE error('the pairs bought together are not counted as expected') END AS verdict;
```

It needs nothing installed beyond DuckDB itself.

## Variants

- Find frequent item sets: Find the sets of items that occur together in many transactions, with their support.
- Derive association rules: Turn frequent item sets into if-then rules scored by confidence, lift or similar measures.
- Find frequent sequences: Find patterns of items that occur in the same order across many sequences of transactions.

## What other tools call it

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

- Alteryx Designer: [`MB Affinity`](https://help.alteryx.com/current/en/designer/tools/predictive-grouping/mb-affinity-tool.html) (read 2026-09-27)
- Alteryx Designer: [`MB Inspect`](https://help.alteryx.com/current/en/designer/tools/predictive-grouping/mb-inspect-tool.html) (read 2026-09-27)
- Alteryx Designer: [`MB Rules`](https://help.alteryx.com/current/en/designer/tools/predictive-grouping/mb-rules-tool.html) (read 2026-09-27)
- KNIME Analytics Platform: [`Association Rule Learner`](https://api.hub.knime.com/nodes/*fPwFWApWDkrJLho6?details=full) (read 2026-09-27)
- KNIME Analytics Platform: [`KNIME Chemistry Add-Ons (extension)`](https://api.hub.knime.com/extensions/org.knime.features.ext.chem.tools) (read 2026-09-27)
- KNIME Analytics Platform: [`KNIME Itemset Mining (extension)`](https://api.hub.knime.com/extensions/org.knime.features.ext.itemset) (read 2026-09-27)
- RapidMiner Studio: [`Create Association Rules`](https://docs.rapidminer.com/latest/studio/operators/modeling/associations/create_association_rules.html) (read 2026-09-27)
- RapidMiner Studio: [`FP-Growth`](https://docs.rapidminer.com/latest/studio/operators/modeling/associations/fp_growth.html) (read 2026-09-27)
- RapidMiner Studio: [`Generalized Sequential Patterns`](https://docs.rapidminer.com/latest/studio/operators/modeling/associations/generalized_sequential_patterns.html) (read 2026-09-27)
- RapidMiner Studio: [`Generate Item Set Indicators`](https://docs.rapidminer.com/latest/studio/operators/blending/attributes/generation/generate_item_set_indicators.html) (read 2026-09-27)
- RapidMiner Studio: [`Item Sets to Data`](https://docs.rapidminer.com/latest/studio/operators/modeling/associations/item_sets_to_data.html) (read 2026-09-27)
- RapidMiner Studio: [`Unify Item Sets`](https://docs.rapidminer.com/latest/studio/operators/modeling/associations/unify_item_sets.html) (read 2026-09-27)
