You can use the LIMIT clause to limit the number of rows returned by a Google Sheets query.
The LIMIT clause is particularly useful when you want to get a glimpse at a few rows that meet some criteria without displaying every row in the entire dataset that meets some criteria.
This clause uses the following basic syntax:
=QUERY(A1:C11, "SELECT * LIMIT 5")
This particular query will return the header row from the range A1:C11 along with the first 5 rows.
The following example shows how to use the LIMIT clause in practice
Example: Using LIMIT in Google Sheets Query
Suppose we have the following dataset that contains information about various basketball players:
We can use the following query to return the header row along with the first five rows in the dataset:
=QUERY(A1:C11, "SELECT * LIMIT 5")
The following screenshot shows how to use this query in practice:
Notice that the header row along with the first five rows are returned.
It’s worth noting that if the query would naturally return less than 5 rows, then the LIMIT clause won’t force the output to display five rows.
For example, suppose we use the following query to display all players who have more than 25 points:
=QUERY(A1:C11, "SELECT * WHERE C > 25 LIMIT 5")
The following screenshot shows how to use this query in practice:
Notice that only two rows are returned because there are only two players in the original dataset that have more than 25 points.
Notice that the LIMIT 5 clause didn’t force the output to have 5 rows.
Rather, the LIMIT clause simply sets a maximum value on the number of rows that will be returned.
Additional Resources
The following tutorials explain how to perform other common operations in Google Sheets:
Google Sheets Query: How to Return Only Unique Rows
Google Sheets Query: How to Remove Header from Results
Google Sheets Query: How to Ignore Blank Cells in Query