Because of the differences between query languages, each data source query editor looks and functions differently.
Depending on your data source, the query editor might provide auto-completion features, metric names, variable suggestions, or a visual query-building interface.
- For data sources included with Grafana, refer to [Built-in core data sources](ref:built-in-core-data-sources), which links to each core data source's documentation.
Saved queries is currently in [public preview](https://grafana.com/docs/release-life-cycle/). Grafana Labs offers limited support, and breaking changes might occur prior to the feature being made generally available.
This feature is only available on Grafana Enterprise and Grafana Cloud. It will gradually roll out to all Grafana Cloud users with no action required. To try out this feature on Grafana Enterprise, enable the `queryLibrary` feature toggle.
You can save queries that you've created so they can be reused by you and others in your organization.
This helps users across your organization create dashboards or find insights in Explore without having to create their own queries or know a query language.
It also helps you avoid having several users build the same queries for the same data sources multiple times.
You can see a list of these queries in the **Saved queries** drawer:
{{<figuresrc="/media/docs/grafana/panels-visualizations/screenshot-saved-queries-v12.2png.png"max-width="550px"alt="List of saved queries and the edit query form"caption="The Saved queries drawer accessed from Dashboards">}}
When you first open the drawer, the list of queries in the **All** tab is filtered by the data source of the panel.
However, you can clear that filter to display all saved queries.
The list in the **Favorites** tab is also filtered by data source, by default.
The **Recent** tab displays the last 20 queries across all data sources from your **Query history** in Explore.
From this tab, you can save queries for reuse as well.
In the **Saved queries** drawer, you can:
- Search for queries by data source name, query content, title, or description.
- Sort queries alphabetically or by creation date.
- Filter by data source name, author name, and tags (the tag filter uses the `OR` operator, while the others use the `AND` operator).
- Set queries as favorites.
- Duplicate, lock and unlock a query for editing, or delete a saved query.
- Edit a query title, description, tags, or the availability of the query to other users in your organization. By default, saved queries are locked for editing.
- When you access the **Saved queries** drawer from Explore, you can use the **Edit in Explore** option to edit the body of a query.
Access the duplicate, lock, unlock, and delete query options through the menu in the top-right corner of the query form next to the **Edit** button.
To access your saved queries, click **+ Add from saved queries** in the query editor:
{{<figuresrc="/media/docs/grafana/panels-visualizations/screenshot-add-from-saved-2-v12.2.png"max-width="750px"alt="Add a saved query">}}
If you've already entered a query, you also have the option to replace it with a saved one:
{{<figuresrc="/media/docs/grafana/panels-visualizations/screenshot-replace-w-saved-v12.2.png"max-width="750px"alt="Replace a query with a saved one">}}
#### Save a query
To save a query you've created:
1. From the query editor, click the **Save query** icon:
{{<figuresrc="/media/docs/grafana/panels-visualizations/screenshot-save-query-v12.2.png"max-width="750px"alt="Save a query">}}
1. In the **Saved queries** drawer, enter a title for the query that will make it easy to find later.
1. (Optional) Enter a description and relevant tags.
1. Clear the **Share query with all users** checkbox if you only want the saved query to be available to you.
1. Click **Save**.
#### Known limitations
- No validation is performed when you save a query, so it's possible to save an invalid query. You should confirm the query is working properly before you save it.
- Saved queries are currently accessible from the query editors in Dashboards and Explore.
- You can save a maximum of 1000 queries.
- Users with the Viewer role who have access to Explore can use saved queries, but can't write them.
- If you have multiple queries open in Explore and you edit one of them by way of the **Edit in Explore** function in the **Saved queries** drawer, the edited query replaces your open queries in Explore.
- Write or construct a query in the query language of your data source.
- Click **+ Add from saved queries** to add a previously saved query.
- If you've already written a query, you can click the **Replace with saved query** icon to use a previously saved query instead.
1. (Optional) To save the query for reuse, click the **Save query** icon.
{{<admonitiontype="note">}}
[Saved queries](#saved-queries) is currently in [public preview](https://grafana.com/docs/release-life-cycle/). Grafana Labs offers limited support, and breaking changes might occur prior to the feature being made generally available.
This feature is only available on Grafana Enterprise and Grafana Cloud.
| {{<figuresrc="/static/img/docs/queries/query-editor-help-7-4.png"max-width="30px"max-height="30px"alt="Help icon">}} | Toggles query editor help. If supported by the data source, click this icon to display information on how to use the query editor or provide quick access to common queries. |
| {{<figuresrc="/media/docs/grafana/panels-visualizations/create-recorded-query-icon.png"max-width="30px"max-height="30px"alt="Create recorded query icon">}} | Create [recorded queries](ref:recorded-queries) so you can see trends over time by taking a snapshot of a data point on a set interval (Enterprise and Cloud only). |
| {{<figuresrc="/media/docs/grafana/panels-visualizations/save-to-query-icon.png"max-width="30px"max-height="30px"alt="Save query icon">}} | Save query. Saves the query so it can be reused. Access saved queries by clicking **+ Add saved query**. For more information, refer to [Saved queries](#saved-queries) (Enterprise and Cloud only). |
| {{<figuresrc="/static/img/docs/queries/duplicate-query-icon-7-0.png"max-width="30px"max-height="30px"alt="Duplicate icon">}} | Copies a query. Duplicating queries is useful when working with multiple complex queries that are similar and you want to either experiment with different variants or do minor alterations. |
| {{<figuresrc="/static/img/docs/queries/hide-query-icon-7-0.png"max-width="30px"max-height="30px"alt="Hide icon">}} | Hides a query. Grafana does not send hidden queries to the data source. |
| {{<figuresrc="/static/img/docs/queries/remove-query-icon-7-0.png"max-width="30px"max-height="30px"alt="Remove icon">}} | Removes a query. Removing a query permanently deletes it, but sometimes you can recover deleted queries by reverting to previously saved versions of the panel. |
| {{<figuresrc="/static/img/docs/queries/query-drag-icon-7-2.png"max-width="30px"max-height="30px"alt="Drag icon">}} | Reorders queries. Change the order of queries by clicking and holding the drag icon, then drag queries where desired. The order of results reflects the order of the queries, so you can often adjust your visual results based on query order. |
If the query returns more data points than the max data points setting, then the data source reduces the number of points returned by aggregating them together by average, max, or another function.
You can limit the number of points to improve query performance or smooth the visualized line.
The default value is the width (or number of pixels) of the graph, because you can only visualize as many data points as the graph panel has room to display.
The **Min interval** corresponds to the min step in Prometheus. Changing the Prometheus interval can change the start and end of the query range because Prometheus aligns the range to the interval. Refer to [Min step](https://grafana.com/docs/grafana/latest/datasources/prometheus/query-editor/#min-step) for more details.
- **Relative time** - Overrides the relative time range for individual panels, which causes them to be different than what is selected in the dashboard time picker in the top-right corner of the dashboard.
- **Cache timeout** - _(Visible only if available in the data source)_ Overrides the default cache timeout if your time series store has a query cache.