# Understanding and Editing the SQL Query

**Key Features of the SQL Section**

#### **1. Editing the SQL Query**

* The SQL query displayed here is either:
  * **AI-generated** based on the selected intent and data sources.
  * **User-defined** if imported from the Data Explorer flow.
* Users can modify the query manually if they need to adjust the dataset.

<figure><img src="/files/JPsn8AzllevStpxOxALi" alt=""><figcaption></figcaption></figure>

***

#### **2. Executing the SQL Query**

* Click **"Execute"** to run the query.
* The system will process the query using the **syntax of the selected data source**.

<figure><img src="/files/hOv3YGculmCjF3D87b69" alt=""><figcaption></figcaption></figure>

***

#### **3. Viewing the Query Results**

* The **Data Table** section displays the results of the executed query.
* This provides a preview of the dataset before applying it to the chart.

<figure><img src="/files/A6bjtORRXr2bxxw3Cq6V" alt=""><figcaption></figcaption></figure>

***

#### **4. Handling Errors & Fixing Issues**

* If there is a **syntax error**, an error message will be displayed.
* The system will provide a **prompt to fix the error**.
* You can manually edit the query or use the AI assistant for corrections.

<figure><img src="/files/XnUYlGIOWWQ4pwElucQW" alt=""><figcaption></figcaption></figure>

***

#### **5. Applying the Query to the Chart**

* Once the query is **error-free**, click the **"Apply"** button.
* This step is **mandatory** as it provisions the dataset for chart customization.

📌 *Without applying the dataset, the chart cannot proceed to customization.*

<figure><img src="/files/r8PvhVtnNjrposB0N6H0" alt=""><figcaption></figcaption></figure>

***

#### **6. Navigating Back to Data Explorer**

* Clicking the **"Explorer"** button takes you back to the **Data Explorer flow**.
* This allows users to refine their dataset before finalizing the chart.

***

### **Next Steps: Customizing Your Chart**

Once the query is successfully applied, you can move to the **Chart Customization** section to configure the visualization settings. 🚀


---

# 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.getinfinity.app/user-guide/comprehensive-user-guide/2.-charts/chart-customization/understanding-and-editing-the-sql-query.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.
