Skip to content

LIMIT and OFFSET clause in BigQuery

Limit and offset are good companion with SELECT (). It can limit the number of rows to return in a query. Optionally includes the ability to skip over rows.

LIMIT: Limits the number of rows to produce. LIMIT 0 returns 0 rows.

OFFSET: Skips a specific number of rows before applying LIMIT.

For example, I want to retrieve only 5 rows from the table.

SELECT *  FROM `instruction-415216.examples.ivys_shop` 
LIMIT  5
RowNameCategoryPriceQuantitySoldPurchase_Price
1KiwiFruit8.8699102.7
2KiwiFruit4.6141352.34
3KiwiFruit0.8574572.56
4KiwiFruit2.739220.95
5KiwiFruit7.5286800.6

For example, I want to skip the top 10 records and retrieve 6 rows.

SELECT *  FROM `instruction-415216.examples.ivys_shop` 
LIMIT 6 OFFSET 10
RowNameCategoryPriceQuantitySoldPurchase_Price
1MangoFruit7.9147191.82
2MangoFruit4.844991.4
3PeachFruit1.0290711.76
4PeachFruit4.339673.58
5PeachFruit4.125251.98
6PeachFruit0.7278440.7