---
title: "Choose and open a query | Grafana Labs"
description: "Sort Queries overview by duration and by errors, narrow to one database, and open one query."
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# Choose and open a query

To choose one query and open it, complete the following steps:

1. Click **Queries overview**.
2. Set the time range to the period when the issue occurred.
3. Click **Duration**.
   
   Sort so the longest queries are at the top. For example, click again if the shortest queries are first. If the table shows no data, change the sort or the time range and continue.
4. Click **Errors**.
   
   If **Errors** is empty for every row, sort by **Duration** only and continue. For example, a high error percentage is a reason to open a query that is not the slowest.
5. Filter to one server.
   
   Open **Filters**, select **instance**, then select **Equals**. Use this when more than one database is listed. The **instance** label names one database server.
6. Select a server from the list.
   
   Choose a server whose database you are allowed to change. If the list has closed, click the filter box to reopen it.
7. Add a second filter when the server hosts more than one database.
   
   Open **Filters** again. On MySQL, select **schema**, **Equals**, and the schema. On PostgreSQL, select **datname**, **Equals**, and the database.
8. Click a query to open its details.
   
   Not all slow queries need optimization. Prioritize based on impact. Impact = Average Duration × Execution Frequency. A query taking 100ms that runs 10,000 times per hour has more impact than a query taking 10 seconds that runs once per day. Focus on queries where high duration and high call frequency overlap, factoring in whether the query is user-facing or on a critical path.

You chose one query and opened its details.
