PostgreSQL – How to limit the number of rows returned by a query

Postgres supports ‘LIMIT’ clause to return only a certain number of rows by a query.

Syntax:

SELECT * from table1 LIMIT 10;

Above statement will return only 10 rows if there are more than 10 rows in the table.

If the table has fewer than 10 rows, all the rows will be returned.

See also  PostgreSQL - Remove all special characters from a string