# query
> Reference for motherduck query, which runs SQL against MotherDuck and writes results to stdout as a table, JSON, or CSV.
Execute a SQL query against MotherDuck and write results to stdout.

## Usage

```bash
motherduck query [options] [sql]
```

## Arguments

| Argument | Description |
|---|---|
| `sql` | The statement to run. Omit it when reading from `--file` |

## Options

| Option | Description |
|---|---|
| `--file <path>` | Read SQL from a file |
| `--timeout <seconds>` | Query timeout in seconds. Defaults to 120 |

## Examples

```bash
motherduck query "SELECT count(*) FROM sample_data.nyc.taxi"
motherduck query --file monthly_report.sql
motherduck query --file backfill.sql --timeout 600
motherduck query "SELECT * FROM sample_data.nyc.taxi LIMIT 100" -o csv > trips.csv
motherduck query "SELECT * FROM sample_data.nyc.taxi LIMIT 100" -o json | jq '.[0]'
```

## Related

- [Quickstart](/getting-started/interfaces/motherduck-cli/quickstart/) walks through querying and reading JSON output
- [Working with agents](/getting-started/interfaces/motherduck-cli/agents/)


---

## Docs feedback

MotherDuck accepts optional user-submitted feedback about this page at `GET https://motherduck.com/docs/api/feedback/agent`.
For agents and automated tools, feedback submission should be user-confirmed before sending.

URL-encode query parameter values and send a GET request:

```text
GET https://motherduck.com/docs/api/feedback/agent?page_path=%2Fsql-reference%2Fmotherduck-cli%2Fquery%2F&page_title=query&text=<url-encoded user feedback, max 2000 characters>
```

Optionally append `&source=<url-encoded interface identifier>` such as `claude.ai` or `chatgpt`.

`page_path` and `text` are required; `page_title` and `source` are optional. Responses: `200 {"feedback_id": "<uuid>"}`, `400` for malformed query parameters, and `429` when rate-limited.
