# Using SQL Blocks

Airbook allows you to retrieve and manipulate data using SQL queries. Below is a step-by-step guide to querying data, using Dataframes, and joining across datasources.

{% embed url="<https://youtu.be/Wlpb36Ff9Ks>" %}

### Querying a Datasource

You can only query one datasource at a time. To join across multiple datasources, see the "Querying and Joining Dataframes" section below.

If you are familiar with SQL, this is the most flexible way to retrieve data. First, select your datasource from the dropdown. The input field will autofill with a basic `SELECT *` query, providing a quick overview of the table contents. Modify the query as needed or run it as-is.

To execute your query, press **Shift + Enter** or click the **Run** button on the right. After a few seconds, a table displaying your results will appear below the input field. This table is referred to as a **Dataframe**.

<figure><img src="/files/Dfus5HlTjkHQUpWbDYYn" alt=""><figcaption></figcaption></figure>

### Working with Dataframes

Each Dataframe has a name, displayed in a green label above the block. You can rename it by clicking on the label and entering a new name. Renaming triggers the query to run again. Your Dataframe is now available for further querying, joining across datasources, charting, and other operations.

### Using the Right Sidebar

The right sidebar helps you browse datasources efficiently:

* Clicking a datasource displays a list of schemas and folders.
* Clicking a table shows its columns and data types.
* Clicking the **Query** button automatically adds a new block with a `SELECT *` query (limited to 100 rows) for a quick table preview.

### The Table View

Once a query runs, its results appear in a table with interactive features:

* **Drag to rearrange columns.**
* **Click a column name to sort and filter data.**
* **Note:** Sorting and filtering here are temporary and do not affect the underlying Dataframe. Filtered-out data is still included in subsequent queries. These tools help explore and refine data before writing new queries.

### Querying and Joining Dataframes

To query a Dataframe, set your datasource dropdown to **Local Dataframes** and use the Dataframe name as the table name in your query. Below are example queries:

```sql
/* Selecting a subset of users from table0 */
SELECT * FROM table0 WHERE table0.age > 25;

/* Joining on a common ID field between two tables */
SELECT * FROM table1 JOIN table2 ON table1.id = table2.id;
```

By following these steps, you can efficiently query, explore, and manipulate data within Airbook.


---

# 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.airbook.io/explore/using-sql-blocks.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.
