View a markdown version of this page

LIMIT and OFFSET clauses - Amazon Athena

LIMIT and OFFSET clauses

LIMIT count returns at most count rows. LIMIT also takes a percentage, such as LIMIT 50% or LIMIT 50 PERCENT, which returns that share of the rows. OFFSET start skips the first start rows, and you can use it with or without LIMIT.

Syntax

LIMIT count [ OFFSET start ] LIMIT percentage { % | PERCENT } [ OFFSET start ] OFFSET start

Examples

For a description of the sample tables that the examples on this page use, see SELECT statement in DuckDB.

The following SQL query skips the first two orders and returns the next two.

SELECT order_id, customer FROM sales_db.sales_parquet ORDER BY order_id LIMIT 2 OFFSET 2

The query returns the following results.

order_id customer

3

carol

4

dave

The following SQL query returns the first half of the orders.

SELECT order_id FROM sales_db.sales_parquet ORDER BY order_id LIMIT 50%

The query returns the following results.

order_id

1

2

3

Considerations

Use ORDER BY with LIMIT and OFFSET. Without it, which rows the query returns is not guaranteed.