# Sort rows

Shape / rows

order rows

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

## Status

Runs as a SQL step.

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

## The DuckDB step

order rows, nulls last

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 row_number() OVER () AS pos, * FROM (SELECT * FROM orders ORDER BY amount DESC NULLS LAST, order_date);
SELECT * FROM result;
SELECT CASE WHEN ((SELECT list(order_id ORDER BY pos) = [6, 8, 3, 10, 1, 7, 2, 5, 9, 4] FROM result)) THEN 'as expected' ELSE error('the rows are not in descending amount with the null last') END AS verdict;
```

It needs nothing installed beyond DuckDB itself.

## Variants

- Order rows by columns: Order the rows by the values of one or more columns or expressions, each ascending or descending, with nulls first or last.
- Move a row by hand: Move one row up, down, or to the top or bottom of the table.
- Reverse row order: Turn the current row order upside down without comparing any values.
- Shuffle rows: Put the rows into a random order.

## 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: [`Sort`](https://learn.microsoft.com/en-us/azure/data-factory/data-flow-sort) (read 2026-09-27)
- Azure Data Factory: [`Sorting`](https://learn.microsoft.com/en-us/azure/data-factory/wrangling-functions) (read 2026-09-27)
- Alteryx Designer: [`Sort`](https://help.alteryx.com/current/en/designer/tools/preparation/sort-tool.html) (read 2026-09-27)
- Apache DataFusion: [`ORDER BY`](https://datafusion.apache.org/user-guide/sql/select.html) (read 2026-09-27)
- Apache DataFusion: [`Sorting (ORDER BY)`](https://datafusion.apache.org/user-guide/features.html) (read 2026-09-27)
- Apache DataFusion: [`sort`](https://docs.rs/datafusion/latest/datafusion/dataframe/struct.DataFrame.html) (read 2026-09-27)
- Apache DataFusion: [`sort_by`](https://docs.rs/datafusion/latest/datafusion/dataframe/struct.DataFrame.html) (read 2026-09-27)
- DuckDB: [`ORDER BY (clause)`](https://duckdb.org/docs/current/sql/query_syntax/orderby) (read 2026-09-27)
- Duckle: [`Sort`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/website/docs/components.html) (read 2026-09-25)
- EasyMorph: [`Sort`](https://help.easymorph.com/doku.php?id=transformations:sort) (read 2026-09-27)
- Apache Hop: [`Sort Rows`](https://hop.apache.org/manual/latest/pipeline/transforms/sort.html) (read 2026-09-27)
- Ibis: [`Sort`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/relations.py) (read 2026-09-27)
- Ibis: [`SortKey`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/sortkeys.py) (read 2026-09-27)
- KNIME Analytics Platform: [`DB Sorter`](https://api.hub.knime.com/nodes/*eTH6FxdMQbNIhJqB?details=full) (read 2026-09-27)
- KNIME Analytics Platform: [`Shuffle`](https://api.hub.knime.com/nodes/*6EpkIj73TcouTxZl?details=full) (read 2026-09-27)
- KNIME Analytics Platform: [`Sorter`](https://api.hub.knime.com/nodes/*gwwIZ5c5EYsJErci?details=full) (read 2026-09-27)
- OpenRefine: [`Reorder rows permanently`](https://openrefine.org/docs/manual/sortview#sort) (read 2026-09-27)
- OpenRefine: [`Sort`](https://openrefine.org/docs/manual/sortview#sort) (read 2026-09-27)
- Pentaho Data Integration: [`Sort rows`](https://docs.pentaho.com/pdia-data-integration/9.3-data-integration/pdi-transformation-steps-reference-overview) (read 2026-09-27)
- Polars: [`DataFrame.reverse`](https://docs.pola.rs/api/python/stable/reference/dataframe/modify_select.html) (read 2026-09-27)
- Polars: [`DataFrame.sort`](https://docs.pola.rs/api/python/stable/reference/dataframe/modify_select.html) (read 2026-09-27)
- Polars: [`Expr manipulation/selection: row ordering (group)`](https://docs.pola.rs/api/python/stable/reference/expressions/modify_select.html) (read 2026-09-27)
- Polars: [`arg_sort_by`](https://docs.pola.rs/api/python/stable/reference/expressions/functions.html) (read 2026-09-27)
- Power Query M: [`Table.ReverseRows`](https://learn.microsoft.com/en-us/powerquery-m/table-functions#row-operations) (read 2026-09-27)
- Power Query M: [`Table.Sort`](https://learn.microsoft.com/en-us/powerquery-m/table-functions#ordering) (read 2026-09-27)
- RapidMiner Studio: [`Shuffle`](https://docs.rapidminer.com/latest/studio/operators/blending/examples/sort/shuffle.html) (read 2026-09-27)
- RapidMiner Studio: [`Sort`](https://docs.rapidminer.com/latest/studio/operators/blending/examples/sort/sort.html) (read 2026-09-27)
- RapidMiner Studio: [`Sort (In Database)`](https://docs.rapidminer.com/latest/studio/operators/extensions/In-Database%20Processing/indb_blending/indb_sort.html) (read 2026-09-27)
- RapidMiner Studio: [`Sort (Multiple)`](https://docs.rapidminer.com/latest/studio/operators/extensions/Operator%20Toolbox/blending/table/sort_multiple.html) (read 2026-09-27)
- RapidMiner Studio: [`Sort by Pareto Rank`](https://docs.rapidminer.com/latest/studio/operators/blending/examples/sort/sort_by_pareto_rank.html) (read 2026-09-27)
- SQLMesh: [`@ORDER_BY`](https://github.com/SQLMesh/sqlmesh/blob/23b237cea7218cc8f338b89c14f0957394a0003b/docs/concepts/macros/sqlmesh_macros.md) (read 2026-09-27)
- Tableau Prep: [`{ ORDERBY }`](https://help.tableau.com/current/prep/en-us/prep_function_reference.htm) (read 2026-09-27)
- Talend: [`tExternalSortOutput`](https://help.qlik.com/talend/en-US/components/8.0/delimited/delimited-component) (read 2026-09-27)
- Talend: [`tExternalSortRow`](https://help.qlik.com/talend/en-US/components/8.0/processing/processing-component) (read 2026-09-27)
- Talend: [`tSortRow`](https://help.qlik.com/talend/en-US/components/8.0/processing/processing-component) (read 2026-09-27)
- Trifacta: [`Sort Transform`](https://help.alteryx.com/aac/en/trifacta-classic/wrangle-language/language-appendices.html) (read 2026-09-27)
- Trifacta: [`Sort rows`](https://help.alteryx.com/aac/en/trifacta-classic/reference/transformation-reference.html) (read 2026-09-27)
- VisiData: [`slide-bottom`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/slide.py#L73) (read 2026-09-23)
- VisiData: [`slide-down`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/slide.py#L69) (read 2026-09-23)
- VisiData: [`slide-down-n`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/slide.py#L77) (read 2026-09-23)
- VisiData: [`slide-top`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/slide.py#L74) (read 2026-09-23)
- VisiData: [`slide-up`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/slide.py#L70) (read 2026-09-23)
- VisiData: [`slide-up-n`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/slide.py#L78) (read 2026-09-23)
- VisiData: [`sort-asc`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/sort.py#L172) (read 2026-09-23)
- VisiData: [`sort-asc-add`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/sort.py#L178) (read 2026-09-23)
- VisiData: [`sort-asc-change`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/sort.py#L180) (read 2026-09-23)
- VisiData: [`sort-desc`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/sort.py#L173) (read 2026-09-23)
- VisiData: [`sort-desc-add`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/sort.py#L179) (read 2026-09-23)
- VisiData: [`sort-desc-change`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/sort.py#L181) (read 2026-09-23)
- VisiData: [`sort-keys-asc`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/sort.py#L174) (read 2026-09-23)
- VisiData: [`sort-keys-asc-add`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/sort.py#L182) (read 2026-09-23)
- VisiData: [`sort-keys-desc`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/sort.py#L175) (read 2026-09-23)
- VisiData: [`sort-keys-desc-add`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/sort.py#L183) (read 2026-09-23)
- VisiData: [`sort-selected-asc`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/experimental/sort_selected.py#L53) (read 2026-09-23)
- VisiData: [`sort-selected-desc`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/experimental/sort_selected.py#L54) (read 2026-09-23)
