# Limit & Sampling

### Limit the output

To limit the output of the query you can use two approaches:

* use the `LIMIT` clause
* set the max size of the data to be returned

```sql
-- limit to 1 record
SELECT *
FROM groceries
LIMIT 1

-- set the data size returned to be 1 megabyte.
SET max.size="1m";

-- on the small dataset we have here 1 MB will accommodate all records added and more
SELECT *
FROM groceries
```

### Set a time limit for a query

To restrict the time to run the query, use `SET max.query.time`:

{% code overflow="wrap" %}

```sql
SET  max.query.time = '1h';

SELECT ...
FROM table
LIMIT 1000
```

{% endcode %}

### Sampling data

To sample data and discard the first rows:

```sql
SELECT *
FROM groceries
LIMIT 1,2
```

This statement instructs Lenses to skip the first record matched and then sample the next two.


---

# 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.lenses.io/latest/user-guide/using/using-sql-to-query-kafka/limit-and-sampling.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.
