# Run a SQL query

Shape / table

run a SQL query over the table

Page: <https://meridian.online/operations/run-a-sql-query>

## Status

Runs as a SQL step.

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

## The DuckDB step

a query over the table, reading the step before it as a CTE chain

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 north AS (SELECT * FROM orders WHERE region = 'north'),
     by_product AS (SELECT product, sum(amount) AS total FROM north GROUP BY product)
SELECT * FROM by_product ORDER BY total DESC;
SELECT * FROM result;
SELECT CASE WHEN ((SELECT count(*) = 3 AND sum(total) = 420.5 FROM result)) THEN 'as expected' ELSE error('the chain did not total 420.50 over three products') END AS verdict;
```

It needs nothing installed beyond DuckDB itself.

## What other tools call it

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

- Bruin: [`SQL assets (family)`](https://getbruin.com/docs/bruin/assets/sql.html) (read 2026-09-27)
- DuckDB: [`CREATE VIEW`](https://duckdb.org/docs/current/sql/statements/create_view) (read 2026-09-27)
- DuckDB: [`SELECT`](https://duckdb.org/docs/current/sql/statements/select) (read 2026-09-27)
- DuckDB: [`WITH (clause)`](https://duckdb.org/docs/current/sql/query_syntax/with) (read 2026-09-27)
- DuckDB: `json_execute_serialized_sql` (read 2026-09-27)
- DuckDB: `query` (read 2026-09-27)
- DuckDB: `query_table` (read 2026-09-27)
- AWS Glue: [`SQL`](https://docs.aws.amazon.com/glue/latest/dg/transforms-sql.html) (read 2026-09-27)
- Apache Hop: [`Spark SQL`](https://hop.apache.org/manual/next/pipeline/transforms/spark-sql.html) (read 2026-09-27)
- Ibis: [`SQLStringView`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/relations.py) (read 2026-09-27)
- Apache NiFi: [`QueryRecord`](https://nifi.apache.org/components/org.apache.nifi.processors.standard.QueryRecord/) (read 2026-09-27)
- Polars: [`DataFrame.sql`](https://docs.pola.rs/api/python/stable/reference/dataframe/modify_select.html) (read 2026-09-27)
- Polars: [`SQL query clauses (group)`](https://docs.pola.rs/api/python/stable/reference/sql/clauses.html) (read 2026-09-27)
- Polars: [`SQLContext`](https://docs.pola.rs/api/python/stable/reference/sql/python_api.html) (read 2026-09-27)
- Polars: [`sql`](https://docs.pola.rs/api/python/stable/reference/expressions/functions.html) (read 2026-09-27)
- Apache SeaTunnel: [`Calcite`](https://seatunnel.apache.org/docs/transforms/calcite) (read 2026-09-27)
- Apache SeaTunnel: [`SQL`](https://seatunnel.apache.org/docs/2.3.13/transforms/sql) (read 2026-09-27)
- SQLMesh: [`SQL models`](https://github.com/SQLMesh/sqlmesh/blob/23b237cea7218cc8f338b89c14f0957394a0003b/docs/concepts/models/sql_models.md) (read 2026-09-27)
