> For the complete documentation index, see [llms.txt](https://docs.getinfinity.app/user-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.getinfinity.app/user-guide/comprehensive-user-guide/2.-charts/chart-customization/understanding-and-editing-the-sql-query.md).

# 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. 🚀
