---
title: "Comment by Jeff Smith on \"Why You Should Avoid Offset in Your DB Queries\" | Hashnode"
description: "When paginating the results of a query in Oracle REST APIs...we don&#39;t actually do that. We take the query...and rewrite it to have the &#39;page&#39; return"
url: "https://hashnode.com/posts/why-you-should-avoid-offset-in-your-db-queries/62700449339f01018101fad0/comment/62728216272fe72a917ccdd4"
---

[Discussion](https://hashnode.com/posts/why-you-should-avoid-offset-in-your-db-queries/62700449339f01018101fad0)

Comment [Why You Should Avoid Offset in Your DB Queries](https://hashnode.com/posts/why-you-should-avoid-offset-in-your-db-queries/62700449339f01018101fad0)

[Jeff Smith](https://hashnode.com/@thatjeffsmith)

[May 4, 2022](https://hashnode.com/posts/why-you-should-avoid-offset-in-your-db-queries/62700449339f01018101fad0/comment/62728216272fe72a917ccdd4)

When paginating the results of a query in Oracle REST APIs...we don't actually do that.

We take the query...and rewrite it to have the 'page' returned as a singular resultset.

So each time the user/app follows the link for the next or previous page, the query is executed again.

So instead of

```
SELECT * FROM my_table
```

We run

```
SELECT *
    FROM (
         SELECT Q_.*,
                ROW_NUMBER() OVER(
                        ORDER BY 1
                ) RN___
            FROM(
                SELECT *
                    FROM my_table
        ) Q_
)
 WHERE RN___ BETWEEN :1 AND :2
```

The API dev can of course override this and build their own logic, or even disable paging...
