The PostgreSQL LIMIT condition is utilized to restrict the information sum returned by the SELECT assertion.
Syntax
The fundamental grammar of SELECT proclamation with LIMIT statement is as per the following −
SELECT column1, column2, columnN
FROM table_name
LIMIT [no of rows]
Coming up next is the punctuation of LIMIT provision when it is utilized alongside OFFSET proviso −
SELECT column1, column2, columnN
FROM table_name
LIMIT [no of rows] OFFSET [row num]
Cutoff and OFFSET permit you to recover only a part of the columns that are created by the remainder of the question.
Example
Consider the table COMPANY having records as follows −
# select * from COMPANY;
id | name | age | address | salary
----+-------+-----+-----------+--------
1 | Paul | 32 | California| 20000
2 | Allen | 25 | Texas | 15000
3 | Teddy | 23 | Norway | 20000
4 | Mark | 25 | Rich-Mond | 65000
5 | David | 27 | Texas | 85000
6 | Kim | 22 | South-Hall| 45000
7 | James | 24 | Houston | 10000
(7 rows)
Coming up next is a model, which restricts the column in the table as indicated by the quantity of lines you need to get from table −
testdb=# SELECT * FROM COMPANY LIMIT 4;
This would deliver the accompanying outcome −
id | name | age | address | salary
----+-------+-----+-------------+--------
1 | Paul | 32 | California | 20000
2 | Allen | 25 | Texas | 15000
3 | Teddy | 23 | Norway | 20000
4 | Mark | 25 | Rich-Mond | 65000
(4 rows)
Be that as it may, in certain circumstance, you may have to get a bunch of records from a specific balance. Here is a model, what gets three records beginning from the third position −
testdb=# SELECT * FROM COMPANY LIMIT 3 OFFSET 2;
This would create the accompanying outcome −
id | name | age | address | salary
----+-------+-----+-----------+--------
3 | Teddy | 23 | Norway | 20000
4 | Mark | 25 | Rich-Mond | 65000
5 | David | 27 | Texas | 85000
(3 rows)
