LIMIT
Use LIMIT to cap the number of rows a query returns, and add OFFSET to skip rows before the limit applies. Because result order isn't guaranteed without sorting, pair LIMIT with ORDER BY to return a stable set of rows.
Syntax
Anchor to Row limit and offsetRow limit and offset
Set the maximum number of rows the query returns. Add OFFSET to skip a number of rows first, which pages through results in fixed-size pages. Pair LIMIT with ORDER BY so the rows you keep are deterministic.
- Anchor to LIMITLIMITLIMITLIMIT <count>LIMIT <count>
Returns at most the specified number of rows.
- Anchor to OFFSETOFFSETOFFSETLIMIT <count> OFFSET <count>LIMIT <count> OFFSET <count>
Skips rows before returning the limited result set.
ShopifyQL
Examples
Description
Rank [`total_sales`](/docs/api/shopifyql/latest/schemas/sales_revenue/sales#salesmetric-propertydetail-totalsales) by product over the last 30 days, keeping only the 10 highest. This example uses `LIMIT 10` to cap the result at ten rows after [`ORDER BY`](/docs/api/shopifyql/latest/syntax/order-by) sorts them.
ShopifyQL
FROM sales SHOW total_sales GROUP BY product_title SINCE -30d UNTIL today ORDER BY total_sales DESC LIMIT 10Description
List [`sessions`](/docs/api/shopifyql/latest/schemas/sessions_and_behavior/sessions#sessionsmetric-propertydetail-sessions) by landing page for last month, skipping the top 10 and returning the next 10. This example uses `LIMIT 10 OFFSET 10` to page through the ranked rows in blocks of ten.
ShopifyQL
FROM sessions SHOW sessions GROUP BY landing_page_path DURING last_month ORDER BY sessions DESC LIMIT 10 OFFSET 10