Sunday , April 28 2024

How To Use Limit And Offset In PostgreSQL

In today’s article, we will examine how to use Limit and Offset clauses and their syntax structures in PostgreSQL.

Offset Clause:

Offset clause is used to skip some records before returning the result set of a query.

We can access the records in the first 20 lines and the next 30 lines with the help of the command below.

In the example above, the data is sorted from smallest to largest with the ORDER BY command, and we wanted to process the records after 20 records with the OFFSET 20 ROWS command.

With the FETCH NEXT 30 ROWS ONLY command, we say to perform the operation on the 30 records after 20.

Limit Clause:

Limit clause is used to restrict the number of rows returned by a query.

For example, if there are 100 records in our table, but we want only 3 records to be returned, we can use the limit clause.

In the example below, we retrieve 5 records from the Address table.

Loading

About Faruk Erdem

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories