> For the complete documentation index, see [llms.txt](https://docs.jetadmin.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.jetadmin.io/classic-app-builder/classic-tutorials/part-2-intermediate/reading-data-from-sql-1.md).

# Reading data from SQL

Let's say, we need to display order total amount on `Customer` table for each customer. All Orders we stored in the separate `Orders` table in the SQL database.&#x20;

The result`Customers`table contains: `customer_id`, `photo`, `name`, `total_amount`columns of data for each customer.

### Build SQL query using SQL Builder

1\. Go to the Component Settings then `Add Data Resource`

![](https://3448227606-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LQ08RFAKZvFADEiXKFy%2F-MGaCnX1IjAQA86jco5F%2F-MGaGGH4oL0pnZ2iIv5V%2FGIF107.gif?alt=media\&token=1e47c8a1-1174-4a86-aca0-f1d27bcd39b8)

2\. Select a resource (SQL database) then choose collection as `Make an SQL request`

![](https://3448227606-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LQ08RFAKZvFADEiXKFy%2F-MGb_OvVEi6xZK9tivS1%2F-MGbbiVX1PFrzeIhkAtx%2FGIF117.gif?alt=media\&token=3a8dd1fb-09b2-4116-8b24-0727316c016c)

### Write SQL query

Let's write a SQL query that returns customers includes the total amount column:

```sql
select 
(select sum(amount) from orders where customer_id = customerscrm.id) as total_amount,
id,
photo,
name
from 
customerscrm
```

![](https://3448227606-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LQ08RFAKZvFADEiXKFy%2F-MGb_OvVEi6xZK9tivS1%2F-MGbcucSNZUlfpiVBir7%2FGIF118.gif?alt=media\&token=88d3d5c4-f1bc-404a-bb9d-0b71387d2d02)

### Tips

Here is a list of your available tables, you can see the table columns. You can use them while writing SQL, just click on the table name and the name will be automatically added.

![](https://3448227606-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LQ08RFAKZvFADEiXKFy%2F-MGb_OvVEi6xZK9tivS1%2F-MGbdbnDARXgDvu6TbTh%2FGIF119.gif?alt=media\&token=4c64361a-82d0-418e-89f5-b9617f90f063)

### Run your SQL query

Simply click `Update Result` button to run your SQL command.

![](https://3448227606-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LQ08RFAKZvFADEiXKFy%2F-MGb_OvVEi6xZK9tivS1%2F-MGbe8JDvVonoeXxltFU%2FGIF120.gif?alt=media\&token=fdf0aed6-c87a-4886-8b56-b0cbfcd98765)

### Customize table

Just close SQL Query Builder to start to customize the result table.

![](https://3448227606-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LQ08RFAKZvFADEiXKFy%2F-MGb_OvVEi6xZK9tivS1%2F-MGbehytc7zFuHma4cMT%2FGIF121.gif?alt=media\&token=b2701a9e-547c-4a4a-80d8-3150651ef8d6)

{% content-ref url="/pages/-MACAp62Ew2HNnkoMkrb" %}
[Making SQL queries](/user-guide/sql-queries-and-api-requests/make-a-sql-query.md)
{% endcontent-ref %}


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.jetadmin.io/classic-app-builder/classic-tutorials/part-2-intermediate/reading-data-from-sql-1.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
