# Sample rows

Shape / rows

random or stratified sample, train and test split

Page: <https://meridian.online/operations/sample-rows>

## Status

Runs as a SQL step.

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

## The DuckDB step

a repeatable sample of four rows

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
SELECT (SELECT list(order_id ORDER BY order_id) FROM (SELECT * FROM orders USING SAMPLE reservoir(4 ROWS) REPEATABLE (42))) AS first_draw,
       (SELECT list(order_id ORDER BY order_id) FROM (SELECT * FROM orders USING SAMPLE reservoir(4 ROWS) REPEATABLE (42))) AS second_draw;
SELECT * FROM result;
SELECT CASE WHEN ((SELECT len(first_draw) = 4 AND first_draw = second_draw FROM result)) THEN 'as expected' ELSE error('the two draws with one seed differ, or a draw is not four rows') END AS verdict;
```

It needs nothing installed beyond DuckDB itself.

## Variants

- Take every nth row: Keep rows at a fixed interval from an offset.
- Other sampling methods: Sample by design or model, sample collections, or write samples aside for checking.
- [Oversample or draw with replacement](https://meridian.online/operations/sample-rows/oversample-or-draw-with-replacement): Draw rows with replacement, or synthesise new minority-class rows, so rows can appear more than in the input.
- Take a random sample: Keep a random number or share of rows, repeatable with a seed, by Bernoulli, system or reservoir sampling.
- Shuffle values at random: Reorder rows, or permute one column's values, at random.
- [Take a stratified sample](https://meridian.online/operations/sample-rows/take-a-stratified-sample): Sample within each class of a column so the sample keeps, or evens out, the class shares.
- [Split rows into training and test sets](https://meridian.online/operations/sample-rows/split-rows-into-training-and-test-sets): Partition every row at random into two or more sets, such as training, validation and holdout.

## 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: [`Create Samples`](https://help.alteryx.com/current/en/designer/tools/preparation/create-samples-tool.html) (read 2026-09-27)
- Alteryx Designer: [`Oversample Field`](https://help.alteryx.com/current/en/designer/tools/preparation/oversample-field-tool.html) (read 2026-09-27)
- Alteryx Designer: [`Random % Sample`](https://help.alteryx.com/current/en/designer/tools/preparation/random---sample-tool.html) (read 2026-09-27)
- DuckDB: [`SAMPLE (clause)`](https://duckdb.org/docs/current/sql/query_syntax/sample) (read 2026-09-27)
- DuckDB: `duckdb_table_sample` (read 2026-09-27)
- Duckle: [`Sample`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/website/docs/components.html) (read 2026-09-25)
- Duckle: [`Sample (Reproducible %)`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/frontend/src/workflow-ui/palette-data.ts) (read 2026-09-25)
- AWS Glue: [`Spigot`](https://docs.aws.amazon.com/glue/latest/dg/aws-glue-api-crawler-pyspark-transforms-spigot.html) (read 2026-09-27)
- AWS Glue: [`Spigot`](https://docs.aws.amazon.com/glue/latest/dg/transforms-configure-spigot.html) (read 2026-09-27)
- Apache Hop: [`Reservoir Sampling`](https://hop.apache.org/manual/latest/pipeline/transforms/reservoirsampling.html) (read 2026-09-27)
- Ibis: [`Sample`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/relations.py) (read 2026-09-27)
- KNIME Analytics Platform: [`Bootstrap Sampling`](https://api.hub.knime.com/nodes/*i1MQOr0EbxLu4c1B?details=full) (read 2026-09-27)
- KNIME Analytics Platform: [`DB Row Sampler`](https://api.hub.knime.com/nodes/*4hFtwIsFE99gW1Q6?details=full) (read 2026-09-27)
- KNIME Analytics Platform: [`DB Table Partitioner`](https://api.hub.knime.com/nodes/*NKuW-RponmBdKGHF?details=full) (read 2026-09-27)
- KNIME Analytics Platform: [`Equal Size Sampling`](https://api.hub.knime.com/nodes/*nZoZFKRELGnk6y5i?details=full) (read 2026-09-27)
- KNIME Analytics Platform: [`Row Sampler`](https://api.hub.knime.com/nodes/*3o-UY2qMENf5piCd?details=full) (read 2026-09-27)
- KNIME Analytics Platform: [`SMOTE`](https://api.hub.knime.com/nodes/*YznaX_v45d3OzPEV?details=full) (read 2026-09-27)
- KNIME Analytics Platform: [`Table Partitioner`](https://api.hub.knime.com/nodes/*T0AhxSe0Yi42rQK8?details=full) (read 2026-09-27)
- KNIME Analytics Platform: [`Target Shuffling`](https://api.hub.knime.com/nodes/*GfRYHsSKd2cu-1Rl?details=full) (read 2026-09-27)
- mlpack: [`Dataset splitting`](https://www.mlpack.org/doc/user/preprocessing.html) (read 2026-09-27)
- Apache NiFi: [`SampleRecord`](https://nifi.apache.org/components/org.apache.nifi.processors.standard.SampleRecord/) (read 2026-09-27)
- Pentaho Data Integration: [`Reservoir Sampling`](https://docs.pentaho.com/pdia-data-integration/9.3-data-integration/pdi-transformation-steps-reference-overview) (read 2026-09-27)
- Polars: [`DataFrame.gather_every`](https://docs.pola.rs/api/python/stable/reference/dataframe/modify_select.html) (read 2026-09-27)
- Polars: [`DataFrame.sample`](https://docs.pola.rs/api/python/stable/reference/dataframe/modify_select.html) (read 2026-09-27)
- Polars: [`Expr manipulation/selection: sampling (group)`](https://docs.pola.rs/api/python/stable/reference/expressions/modify_select.html) (read 2026-09-27)
- RapidMiner Studio: [`SMOTE Upsampling`](https://docs.rapidminer.com/latest/studio/operators/extensions/Operator%20Toolbox/blending/smote.html) (read 2026-09-27)
- RapidMiner Studio: [`Sample`](https://docs.rapidminer.com/latest/studio/operators/blending/examples/sampling/sample.html) (read 2026-09-27)
- RapidMiner Studio: [`Sample (Bootstrapping)`](https://docs.rapidminer.com/latest/studio/operators/blending/examples/sampling/sample_bootstrapping.html) (read 2026-09-27)
- RapidMiner Studio: [`Sample (Collection)`](https://docs.rapidminer.com/latest/studio/operators/extensions/Operator%20Toolbox/blending/table/sample_collection.html) (read 2026-09-27)
- RapidMiner Studio: [`Sample (In Database)`](https://docs.rapidminer.com/latest/studio/operators/extensions/In-Database%20Processing/indb_blending/indb_sampling.html) (read 2026-09-27)
- RapidMiner Studio: [`Sample (Kennard-Stone)`](https://docs.rapidminer.com/latest/studio/operators/blending/examples/sampling/sample_kennard_stone.html) (read 2026-09-27)
- RapidMiner Studio: [`Sample (Model-Based)`](https://docs.rapidminer.com/latest/studio/operators/blending/examples/sampling/sample_model_based.html) (read 2026-09-27)
- RapidMiner Studio: [`Sample (Stratified)`](https://docs.rapidminer.com/latest/studio/operators/blending/examples/sampling/sample_stratified.html) (read 2026-09-27)
- RapidMiner Studio: [`Split Data`](https://docs.rapidminer.com/latest/studio/operators/blending/examples/sampling/split_data.html) (read 2026-09-27)
- Tableau Prep: [`Data sample`](https://help.tableau.com/current/prep/en-us/prep_configure_dastaset.htm) (read 2026-09-27)
- Talend: [`tReservoirSampling`](https://help.qlik.com/talend/en-US/components/8.0/sampling/sampling-component) (read 2026-09-27)
- Talend: [`tSample`](https://help.qlik.com/talend/en-US/components/8.0/processing/processing-component) (read 2026-09-27)
- VisiData: [`random-rows`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/random_sample.py#L3) (read 2026-09-23)
