A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/postgresql/postgresql-limit-clause/ below:

PostgreSQL - LIMIT clause - GeeksforGeeks

PostgreSQL - LIMIT clause

Last Updated : 12 Jul, 2025

The PostgreSQL LIMIT clause is a handy tool used to fetch a specific subset of rows returned by a query. This clause is optional and can be a powerful way to control the amount of data your query returns, especially when working with large datasets.

Let us better understand the LIMIT Clause in PostgreSQL from this article.

Syntax
SELECT * FROM table_name LIMIT n;
Parameters

Now let's analyze the syntax above:

PostgreSQL LIMIT clause Examples

For the sake of this article we will be using the sample DVD rental database, which is explained here and can be downloaded by clicking on this link. Now, let's look into a few examples.

Example 1: Fetching the First 10 Films

In this example we will be using the LIMIT clause to get the first 10 films ordered by the "film_id" from the "film" table of our sample database.

Query:

SELECT
    film_id,
    title,
    rating
FROM
    film
ORDER BY
    film_id
LIMIT 10;

Output:

Explanation: This query will return the first 10 films based on their 'film_id'.

Example 2: Fetching the Top 10 Most Expensive Films

In this example we will be using the LIMIT clause to get the top 10 expensive films ordered by the "rental_rate" from the "film" table of our sample database.

Query:

SELECT
    film_id,
    title,
    rental_rate
FROM
    film
ORDER BY
    rental_rate DESC
LIMIT 10;

Output:

Explanation: This query will return the top 10 films with the highest rental rates.

Important Points About PostgreSQL LIMIT clause


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4