> ## Documentation Index
> Fetch the complete documentation index at: https://docs.erdo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Dataset views

> A dataset whose rows are a SQL query over another dataset, so a page or a teammate sees only the columns and rows you choose

# Dataset views

A **view** is a dataset whose rows come from a SQL query over another dataset. It has no
copy of its own: the query runs each time someone reads the view, so it is always as
current as the dataset underneath it.

Use a view when someone should see part of a dataset and not the rest. The common case is
a page. Anyone who can open a page can query every dataset the page is bound to, all
columns and all rows, not only what the page displays. For a public page that means anyone
with the link. Bind the page to a view instead, and visitors can read only what the view
selects.

For example, a public dashboard that shows how many leads each landing-page variant
brought in needs a count per variant. It does not need each lead's email address. A view
of the leads dataset gives it exactly that:

```sql theme={null}
SELECT variant, count(*) AS leads
FROM data
GROUP BY variant
```

Inside a view's query, `data` is the dataset the view reads. When someone reads the view,
`data` is the view's own output, so a query against the view can only reach the columns
the view selects.

## What a view guarantees

* **Readers need access to the view, not to the source.** A teammate, a shared thread or a
  page can be given the view while the source stays private.
* **The source's filters still apply.** Rows hidden by the source dataset's
  [filters](https://docs.erdo.ai/filters.md), such as test submissions, never appear in a view of it, and a reader
  of the view cannot switch them off.
* **A view lasts only as long as its creator's access.** If the person who created the view
  can no longer see the source dataset, the view stops returning rows and says why.
* **A view is read-only.** Write to its source dataset instead. A view has no refreshes, no
  revisions and no schema of its own to edit: its columns come from its query.

Views can read **file datasets**: uploads, lead and form capture, and tables Erdo writes.
They cannot read another view, or a dataset synced from a connected app. The source needs at
least one row before you create a view of it, because the view's columns come from running its
query.

A view stays with its source. You can't delete a dataset while views read it (Erdo names them),
and you can't move a view, or a dataset that views read, to another organization. Delete the
views first, or recreate them in the other organization.

You can add [filters](https://docs.erdo.ai/filters.md) to a view like any other dataset. They apply to the
view's output.

## Creating a view

In chat, ask Erdo to make a view, for example "make a view of our leads with just the count
per variant, for the public dashboard". Erdo creates it and uses it in place of the leads
dataset when it builds the page.

```bash CLI theme={null}
erdo datasets view create acme.leads \
  --name "Leads by variant" \
  --sql "SELECT variant, count(*) AS leads FROM data GROUP BY variant"

# Read the query from a file
erdo datasets view create acme.leads --name "Leads by variant" --sql @leads-by-variant.sql
```

```bash REST theme={null}
curl -X POST -H "Authorization: Bearer $ERDO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "Leads by variant", "view": {"source_dataset": "acme.leads", "sql": "SELECT variant, count(*) AS leads FROM data GROUP BY variant"}}' \
  https://api.erdo.ai/v1/datasets-create
```

Over MCP, call `erdo_create_dataset` with a `view` object holding `source_dataset` and
`sql`. You need view access to the source dataset to create a view of it.

Read a view the way you read any dataset: `erdo datasets query`, `erdo_query_data`, or
`POST /v1/datasets/:slug/query`.

> [!NOTE]
>
> Views are being rolled out gradually. If creating one says views are not enabled for your
> account, contact Erdo support.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.