Subquery with offset and limit
Now we can also achieve this thing with Subquery without using Row Number but in that we will be using offset and limit. In which offset will be used to mark the row from which the reading of data will be started and Fetch will take the next and return it to the result set.
SELECT *
FROM employees
OFFSET (SELECT COUNT(*) * 3 / 4 FROM employees)
FETCH NEXT (SELECT COUNT(*) / 4 FROM employees) ROWS ONLY;
Output:
Explanation: In this we have applied the same subquery twice over here. For offset it will assign the number to each of the data. And fetch will only fetch the required rows.
List the Last 25% Rows in a Result Set in PostgreSQL
In PostgreSQL, extracting specific portions of a result set can be achieved using a variety of SQL techniques. One common requirement is to retrieve the last 25% of rows from a result set. This can be useful for various purposes, such as paginating results, performing analyses on a subset of data, or optimizing queries for performance.
Contact Us