Google Sheets QUERY: Limit the Number of Rows

LIMIT and OFFSET

It is possible to limit the number of rows returned by the QUERY function using LIMIT.

If needed, OFFSET allows shifting the data display by starting at a row number different from 1.


LIMIT

For example, to obtain the first 5 result rows, add LIMIT at the end of the query followed by the maximum number of rows to return:

=QUERY(DB!A1:G15,"SELECT * LIMIT 5")
google sheets query function limit

OFFSET

The first example allowed us to retrieve the first 5 rows of results. The goal now is to retrieve the next 5 rows.

In this case, you need to add the same limit as well as OFFSET followed by the number of rows to shift:

=QUERY(DB!A1:G15,"SELECT * LIMIT 5 OFFSET 5")
google sheets query function limit offset

Top X

For example, to get the top 3 users with the most messages (E), use ORDER BY with LIMIT:

=QUERY(DB!A1:G15,"SELECT * ORDER BY E DESC LIMIT 3")
google sheets query function limit order by

Order

The order to follow to build a query is as follows:

SELECT > WHERE > GROUP BY > ORDER BY > LIMIT > OFFSET