# Query Rows

The Query Rows action retrieves rows from your Google Spreadsheet. To get started, [Authenticate](/connect/google-sheets.md) and select an existing Spreadsheet and Sheet. Then click the Retrieve Fields button to retrieve the columns from your spreadsheet. These columns will be available as variables in future steps in your workflow.

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

## Basic filtering

You can choose to fetch all of the rows in your spreadsheet, or you can filter the rows returned by specific values. For basic filters, use the Filter rows by column value option pictured above. The Column value will pre-populate with the columns from your spreadsheet, and you can select columns that equal, do not equal, or contain a specific value.

MESA will use the header values detected when you last clicked the Retrieve Fields button in the builder.

> Tip: Depending on your plan, the Loop step generally will time out after about 200 records. If your spreadsheet has more than 200 rows, we suggest filtering your rows in the Google Sheets Query Rows step.

## Advanced filtering

To filter by multiple column values, specify a specific subset of columns that should be returned, or to run advanced queries that calculate the sum or average value of columns, use the Advanced query option and enter a [Google Sheets Query Language](https://developers.google.com/chart/interactive/docs/querylanguage) query in the input.

Because the result of a query doesn't always match your header row, MESA will use the A, B, C, ... column representation as keys for your response.

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

### Query examples

Here are a few basic examples of Query Language queries based on the spreadsheet below. Additional examples can be found in the [Query Language docs](https://developers.google.com/chart/interactive/docs/querylanguage).

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

#### Return records that match multiple filter criteria (and):

```sql
select * where B="Oakland" and C>100
```

This will return a single row (Row 2).

#### Return records with multiple options (or)

```sql
select * where B="Oakland" or B="San Francisco"
```

This will return three rows (Row 2 and 3).

#### Calculate the total value of a column

```sql
select sum(C) where B="Oakland"
```

This will return a single record with one value, the total of C2 + any other row where Oakland was the City.


---

# 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.getmesa.com/connect/google-sheets/query-rows.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.
