# 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`

![](/files/-MGaGGH4oL0pnZ2iIv5V)

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

![](/files/-MGbbiVX1PFrzeIhkAtx)

### 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
```

![](/files/-MGbcucSNZUlfpiVBir7)

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

![](/files/-MGbdbnDARXgDvu6TbTh)

### Run your SQL query

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

![](/files/-MGbe8JDvVonoeXxltFU)

### Customize table

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

![](/files/-MGbehytc7zFuHma4cMT)

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


---

# 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.jetadmin.io/getting-started/part-2-intermediate/reading-data-from-sql-1.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.
