Google Sheets QUERY has no direct OFFSET clause, but you can skip rows by wrapping the QUERY in another QUERY with a LIMIT and OFFSET, or by using the LABEL clause to remove header rows. The simplest way is: =QUERY(QUERY(A1:C, "select *", 1), "offset 5", 0) which skips the first 5 data rows of the inner result.
What OFFSET Does in SQL and Why Sheets Lacks It
In standard SQL, OFFSET is used with LIMIT to paginate results, like LIMIT 10 OFFSET 20 to get rows 21-30. Google Sheets QUERY is based on the Google Visualization API Query Language, which supports LIMIT but not OFFSET. This means you cannot directly write select * offset 5 in a single QUERY. The workaround is to nest QUERY functions, using the inner QUERY to process your data and the outer QUERY to skip a number of rows.
How to Skip Rows with Nested QUERY
To skip the first N rows of a result, wrap your original QUERY inside another QUERY and use the OFFSET clause in the outer one. The inner QUERY can be as simple as selecting all columns, or it can include filtering, sorting, and aggregation. The outer QUERY then applies OFFSET to the inner result.
- Basic example:
=QUERY(QUERY(A1:C, "select *", 1), "offset 2", 0)skips the first 2 data rows of the range A1:C (after the header). - With filtering:
=QUERY(QUERY(A1:C, "where B > 100", 1), "offset 3", 0)skips the first 3 rows that meet the condition. - With sorting:
=QUERY(QUERY(A1:C, "order by A desc", 1), "offset 1", 0)skips the top row after sorting descending.
Note that the third argument in the inner QUERY (1) tells it that the data has a header row. The outer QUERY’s third argument (0) tells it that the input has no header, so it treats the first row of the inner result as data, which is what you want when skipping rows.
Using OFFSET with LIMIT for Pagination
To get a specific page of results, combine LIMIT and OFFSET in the outer QUERY. For example, to get rows 11-20 of a sorted list, use =QUERY(QUERY(A1:C, "order by A", 1), "limit 10 offset 10", 0). This is useful for building dashboards or displaying a subset of data. Remember that the inner QUERY processes the entire range first, so performance may degrade with very large datasets.
Removing Header Rows with LABEL
Sometimes you don’t need to skip data rows but want to remove the header row from the output. The LABEL clause can set a header to an empty string, effectively hiding it. For example, =QUERY(A1:C, "select * label A ''", 1) removes the header for column A. To remove all headers, you can use label A '', B '', C ''. This is not OFFSET, but it solves a common confusion where users think they need to skip the first row.
Common Errors and How to Fix Them
- #VALUE! error: This happens if you use OFFSET directly in a single QUERY, like
=QUERY(A1:C, "select * offset 2", 1). The query language doesn’t support OFFSET, so it throws an error. Use the nested approach. - Wrong number of rows skipped: If you set the inner QUERY’s header argument to 0 when your data has a header, the first row of data will be treated as a header and skipped incorrectly. Always match the header argument to your actual data.
- OFFSET larger than data: If you skip more rows than exist, the result is empty. You can wrap the outer QUERY in an IFERROR to show a friendly message, like
=IFERROR(QUERY(QUERY(A1:C, "select *", 1), "offset 100", 0), "No more rows").
Comparison with Excel’s OFFSET Function
Excel has a native OFFSET function that returns a range of cells, but it’s different from SQL’s OFFSET. In Excel, =OFFSET(reference, rows, cols, height, width) returns a range shifted from a starting cell. For example, =OFFSET(A1, 2, 0, 5, 1) returns the range A3:A7. This is not row skipping in a query sense; it’s a dynamic range reference. In Google Sheets, you can also use the OFFSET function, but it’s rarely needed for QUERY pagination. If you’re migrating from Excel, note that the QUERY function has no direct equivalent to Excel’s OFFSET in a filtering context.
Performance and Best Practices
Nested QUERY functions can slow down large spreadsheets because each QUERY scans the entire range. To optimize, limit the range in the inner QUERY as much as possible, e.g., QUERY(A1:C, "select * where A is not null", 1) to ignore empty rows. Also, avoid using OFFSET to skip many rows when you can filter them out with a WHERE clause instead. For example, if you want to skip the first 10 rows based on a date, use where date > '2023-01-01' rather than OFFSET. If you need to paginate a large dataset, consider using the FILTER function with SORTN or a helper column with row numbers, which can be more efficient.
Frequently Asked Questions
Can I use OFFSET in Google Sheets QUERY directly? No, the QUERY language does not support OFFSET. You must nest QUERY functions as shown above.
How do I skip the first 10 rows in QUERY? Use =QUERY(QUERY(A1:C, "select *", 1), "offset 10", 0). Replace A1:C with your actual range.
Why does my QUERY return an error when I add OFFSET? Because OFFSET is not a valid clause in the QUERY language. Remove it and use the nested approach.
Does OFFSET work with WHERE and ORDER BY? Yes, you can combine them in the inner QUERY, then apply OFFSET in the outer QUERY. For example, =QUERY(QUERY(A1:C, "where B > 100 order by A", 1), "offset 2", 0).
Is there a way to skip rows without using QUERY? Yes, you can use the FILTER function combined with ROW numbers, or use the SORTN function with a skip parameter, but QUERY with nesting is often the most straightforward for complex conditions.
What is the difference between OFFSET and LABEL in QUERY? OFFSET skips data rows, while LABEL changes or removes header labels. They serve different purposes; you can use both together, e.g., =QUERY(QUERY(A1:C, "select * label A 'ID'", 1), "offset 1", 0).
Related
- Data Entry Software for PC: Top Picks & How to Choose
- Google Sheets Protect Range: How to Lock Cells
- Node.js Generate Random 6 Digit Number: 3 Ways
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- Snowflake SPLIT: Turn a String Into an ArrayYes. In Snowflake, use SPLIT(string, delimiter) to divide a string at each occurrence of a delimiter and return…
- Google Sheets Inventory Spreadsheet: Setup and TipsYes. Google Sheets can serve as an inventory spreadsheet for a small shop, office, classroom, or household: list…
- Excel Slicers for Multiple Tables: What WorksYes, an Excel slicer can control multiple PivotTables when they share a compatible PivotTable cache or use the…
- Excel Remove Duplicates: Why No Duplicates Are Found and What to CheckIf Excel’s Remove Duplicates command reports that no duplicates were found, it means no two rows matched across…
- Ctrl+E in Excel: Flash Fill Shortcut and How It WorksIn Excel for Microsoft 365 on Windows, Ctrl+E runs Flash Fill: it detects a pattern in your examples…
- Excel Table Colors: How to Change and Customize ThemExcel table colors are controlled mainly by table styles: select a cell in the table, open the Table…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.