# Query

There are two main types of queries:

1. [Streaming or Continuous Queries](#_streaming_or_continuous_query)
2. [Queries on Materialized Views](#query-on-materialized-views)

In the DeltaStream UI **Query** tab, or when [listing queries with the CLI](/reference/sql-syntax/command/list-queries.md), DeltaStream displays only long-running streaming queries. Queries on materialized views are snapshot queries and therefore not long-lived.

{% hint style="info" %}
**Note** In DeltaStream, SQL queries that actually process data are just called queries.
{% endhint %}

## Streaming or Continuous Queries <a href="#streaming_or_continuous_query" id="streaming_or_continuous_query"></a>

In DeltaStream, a streaming or continuous query does the following:

1. reads from one or more [streams](/overview/core-concepts/databases.md#_stream) and/or [changelogs](/overview/core-concepts/databases.md#_changelog)
2. processes the data according to the query logic
3. generates one or more streams or changelogs

Streaming queries are continuous. When you start them they keep running until you explicitly terminate them.

Streaming queries themselves take two forms in DeltaStream:

1. **Persistent streaming (continuous) queries:** These queries persist the results in the streaming storage by creating new streams or changelogs.
2. **Interactive streaming (continuous) queries:** When you start these queries, they run continuously and stream the results of the query to you.

Streaming queries start in the `NEW` state. When you run them they transition to the `RUNNING` state. At this point they process records from the source object(s) and write into the sink object. When a streaming query fails or otherwise stops operating, it displays as an `ERRORED` state.

The system may automatically restart a query if it detects an underlying problem, such as a network issue. In failure scenarios, DeltaStream restarts queries from the last known state, at which point they proceed to operate normally.

{% hint style="info" %}
**Note** You can report back unrecoverable failures either via the [DESCRIBE QUERY](/reference/sql-syntax/command/describe-query.md) command or by clicking on the query state in the DeltaStream Web app.
{% endhint %}

If you terminate a query on your own, DeltaStream considers the query complete and performs system cleanup.

See [Query](/reference/sql-syntax/query.md) for a list of statements that can start a query for processing records within a [Data Store](/overview/core-concepts/store.md).

## Query on Materialized Views

When you build a [Materialized View](/overview/core-concepts/databases.md#_materialized_view) in DeltaStream, you can use standard SQL queries to query the content of the view. Unlike continuous queries, queries on materialized views compute and return results based on the content of the view at the time you issue the query. These queries behave like the queries on tables in traditional relational databases.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.deltastream.io/overview/core-concepts/queries.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
