What is Offset in SQL

With 9+ years in SEM and data automation, Piyush Nair helps businesses and individuals simplify processes using Google Sheets, Excel, Apps Script, and other productivity tools, turning data into actionable insights

What is OFFSET and how to use in SQL

This post explains you what is offset in SQL and how to use it.

Offset function in SQL is use to do pagination. If your database has thousands of rows, and you want to view data from specific number of row then you use this function.

It is often used with Limit function, which decides count of rows you want to view.

When OFFSET is useful

OFFSET becomes valuable in scenarios where you want to skip a certain number of rows before displaying results. Common use cases include :

  • Dashboard reports – Load data page by page instead of all at once.
  • Admin panels – View users, orders, logs, or transactions in pages.
  • Analytics tools – Navigate through data without overwhelming the system.
  • Testing queries – View results beyond the first few rows.
  • Sampling data – Skip early rows and inspect specific segments.

Syntax

SELECT columns
FROM table
ORDER BY column
LIMIT number OFFSET number

Explanation

SELECT columns = select all the columns present in the table
FROM table = Table name in which above requested columns are present
ORDER BY column = summarize the data based on the columns
LIMIT OFFSET = limit the rows you want to view and after which row you want data from

Theoretical Example

SELECT *
FROM employees
ORDER BY employee_id
LIMIT 10 OFFSET 20

Practical Example

Below image shows all rows and column from table name : employees

Below example shows how to use OFFSET in SQL. We have limited the rows to 3 and fetching data from row 2 onwards

When not to use OFFSET function

While OFFSET works well for small and medium-sized tables, it has limitations

OFFSET gets slower as the number grows

To skip 50,000 rows, the database still reads those rows internally.
This means:

  • OFFSET 0–100 → very fast
  • OFFSET 50,000 → much slower
  • OFFSET 1,000,000 → significantly slow on large datasets

Conclusion

Would suggest you use offset function as it will improve your efficiency in data pulling and de-clutter your data set when data set is smaller.

More Blogs!!

Learn Google Sheets – Basic to Advance
How Does VLOOKUP Work ?
Everything about Pivot Table in Google Sheets

Discover more from DataInNutShell

Subscribe now to keep reading and get access to the full archive.

Continue reading

Discover more from DataInNutShell

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%