> For the complete documentation index, see [llms.txt](https://docs.fabricplan.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fabricplan.com/planning-sheets/how-tos/infobridge/query-transformations/sql-queries.md).

# SQL queries

Use **SQL Query** to create a new query by writing SQL statements against an existing Infobridge query.

SQL queries let you retrieve specific columns, filter data, and reshape query results without modifying the original query.

{% hint style="info" %}
SQL queries create a new query. They don't modify the original Infobridge query.
{% endhint %}

### Example scenario

This example creates a new SQL query named **High Value Product Sales** from an existing planning sheet query.

The SQL query retrieves the product, category, country/region, units, unit price, and revenue columns from the source query.

### Create a SQL query

This example shows how to create a new SQL query from an existing Infobridge query.

1. On the **Home** ribbon, select **SQL Query**.<br>

   <figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2F0uJBCPuhAqBL2HfKSzFd%2Fselect-sql-query.png?alt=media&amp;token=73859f77-b3c1-4b93-9078-3c779516245e" alt=""><figcaption></figcaption></figure>
2. In **Source Name**, enter **High Value Product Sales**.<br>

   <figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FcWL3VFSOFoBWT2do3Ols%2Fopen-create-sql-query-dialog.png?alt=media&amp;token=c0a842e4-55e4-4bf0-accc-3af85bbcb7dc" alt=""><figcaption></figcaption></figure>
3. Under **Query References**, on the **Reference** tab, select **Query 1 - Planning 1**.<br>

   <figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2F7ZUuibyvLt8Q04KuHFth%2Fselect-query-reference.png?alt=media&amp;token=4df41aa6-5015-4c8f-9103-7722b011fd7f" alt=""><figcaption></figcaption></figure>
4. In **SQL Query**, enter the following SQL statement.<br>

   ```sql
   SELECT
       ProductName,
       Category,
       Ctry,
       Units,
       "Unit Price",
       Revenue
   FROM {{query_id:1}}
   ```

   <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p>Add query references by using the <strong>Query References</strong> pane or by entering <code>{{query_id:1}}</code> directly in the SQL statement.</p></div>
5. Select **Create**.<br>

   <figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FuYdgBuF9GqDG6A8HvTks%2Fsql-query-created.png?alt=media&amp;token=9b11e7a4-4bb3-4aa1-99bb-2de56a573f2d" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.fabricplan.com/planning-sheets/how-tos/infobridge/query-transformations/sql-queries.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
