# SQL Processing

Run SQL queries or modify data in MatrixOne, returning query results or affected row counts.

Use it for filtering, aggregation, and data transformation. To read a selected table, use [Read MOI Table](../data-io/read-table.md).

## Configure SQL

SQL is required and must be nonempty. Optionally select a Catalog `table_ref` and reference it with `${source_table}`.

```sql
SELECT * FROM ${source_table} LIMIT 100
```

The node replaces this placeholder with the selected table's fully qualified name. Using the placeholder without binding a table causes the node to fail.

Keep the `${source_table}` syntax for the selected table. Double braces reference workflow variables; see [Variables and data flow](../../variables-and-data.md).

## Use the output

Queries return `rows` as objects keyed by column name. Data-changing statements return `affected_rows` when supplied by the backend. `sql` is the executed statement, and `elapsed_ms` is its duration.

When a table is bound, the output also includes its reference, database, name, and expanded `source_table`. Check `truncated` for incomplete query results.

Inserts, updates, and deletes change database contents. Confirm the target and filter conditions before running them.

## Example: save a query sample

Flow: SQL Processing → Save to MOI Volume.

Select a source table and use the query above. Save `rows` with matching column names as CSV.

## Related pages

- [Variables and data flow](../../variables-and-data.md)
- [Run and debug](../../run-debug.md)
