> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dust.tt/llms.txt
> Use this file to discover all available pages before exploring further.

# Table queries

> Let an agent answer quantitative questions by writing and running SQL on your tables, spreadsheets, and databases.

With **Analytics**, the agent turns a question into a SQL query, runs it on the tables you selected, and answers from the results. Use it for questions about numbers, counts, and trends, where search falls short because it only reads the passages it finds. For questions about text, like policies or notes, use [search](https://docs.dust.tt/docs/user-documentation/agents/knowledge/search-data-sources.md) instead.

## When to use table queries

Take this table of cars:

| car | production\_year | color | description |
| - | - | - | - |
| toyota | 2001 | red | Perfect car for young people who love the city |
| mercedes | 2004 | red | Perfect car if you love fancy things |
| volkswagen | 2008 | blue | A great car if you like the countryside |
| renault | 2012 | brown | Ideal car if you like going to your local repair shop |
| citroen | 2020 | green | A great car if you don't like cars |

"What is the most common color for cars produced between 2000 and 2010?" is a good fit for a table query. "What is the best car to buy if I live in New York?" is a better fit for search, because the answer is in the descriptions.

## Where tables come from

* **Folders**: upload a CSV or Excel (.xlsx) file as a table, or create tables with the API ([Upsert a table](https://docs.dust.tt/api-reference/datasources/upsert-a-table.md)).
* **Connections**: Dust creates tables from Google Sheets (each tab becomes a table), Microsoft Excel files, Notion databases, Salesforce, Snowflake, and BigQuery.

Each Google Sheets tab can have up to 512 columns. See the Google Drive [size limitations](https://docs.dust.tt/docs/user-documentation/admins/connections-management/google-drive.md#size-limitations) for the other limits on Google Sheets.

You don't need this setup for CSV or Excel files uploaded in a conversation: the agent analyzes them in the conversation. See [Conversation files](https://docs.dust.tt/docs/user-documentation/data-sources/conversation-files/conversation-files.md).

## Set up table queries

**1. Add knowledge**

In the Agent Builder, in **Capabilities and knowledge**, click **Add knowledge**.

**2. Select tables**

Pick a Space and select one or more tables. Select a whole spreadsheet to add all of its tabs. Click **Next**.

**3. Choose Analytics**

Pick **Analytics (tables, spreadsheets...)**, describe what the tables contain, and save the agent.

> [!NOTE]
>
> The agent uses the tables selected when you save it. When you select a spreadsheet or a folder, Dust adds the tabs or tables directly inside it at that moment. Tables in nested subfolders aren't included. If you add tabs or tables later, edit the agent, select them, and save.

## Describe your tables

A clear description helps the agent write better queries. For a table like this one:

| name | date | stage |
| - | - | - |
| ACME CORP | 20/10/2022 | lead |
| STARK CORP | 21/11/2023 | closing |
| PERMUTATION LABS | 19/08/2020 | customer |

A good description would be: "Extract from our CRM. Each row is a potential customer, with the date of our last meeting and their stage in the sales pipeline."

For BigQuery, you can reuse the table and column descriptions set in BigQuery. Turn this on in the BigQuery connection settings.

## Join tables

An agent can use several tables at once and join them, even when they come from different data sources. Select all the tables when you set up the knowledge, then explain in the instructions how they relate.

For example, with a `users` table (`name`, `email`) and an `orders` table (`product_name`, `user_email`), add this to the instructions:

```
You can join the users and orders tables on users.email and orders.user_email.
```

This matters most when the right join columns aren't obvious from their names.

## Related

> [card] [Knowledge](https://docs.dust.tt/docs/user-documentation/agents/knowledge)
>
> Compare the ways an agent can use your data.

> [card] [Search data sources](https://docs.dust.tt/docs/user-documentation/agents/knowledge/search-data-sources.md)
>
> Search text documents by meaning.

> [card] [Folders](https://docs.dust.tt/docs/user-documentation/data-sources/folders.md)
>
> Upload CSV files and create tables.

> [card] [Upsert a table](https://docs.dust.tt/api-reference/datasources/upsert-a-table.md)
>
> Create and update tables with the API.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.