SQLite Limit clause
SQLite's LIMIT clause is used to limit the amount of data returned by a SELECT statement.
Grammar
The basic syntax of a SELECT statement with a LIMIT clause is as follows:
SELECT column1, column2, columnN
FROM table_name
LIMIT [no of rows]
FROM table_name
LIMIT [no of rows]
The following is the syntax of the LIMIT clause when used with the OFFSET clause:
SELECT column1, column2, columnN
FROM table_name
LIMIT [no of rows] OFFSET [row num]
FROM table_name
LIMIT [no of rows] OFFSET [row num]
The SQLite engine will return all rows starting from the next row up to the given OFFSET, as shown in the last example below Show.
Example
Assuming the COMPANY table has the following records:
# ID name Age Address Salar
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------- ----------- ---------- ----------
1 " Paul " 32 " California 20000.0
2 " Allen 25 Texas 15000.0
3 Teddy 23 NORWAY 20000.0 ## 4 Mark 25 Rich-Mond 65000.0
5 David 27 TEXAS 85000.0
6 KIM 22 South-Hall 45000.0
7 Jamest On 10000.0
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------- ----------- ---------- ----------
1 " Paul " 32 " California 20000.0
2 " Allen 25 Texas 15000.0
3 Teddy 23 NORWAY 20000.0 ## 4 Mark 25 Rich-Mond 65000.0
5 David 27 TEXAS 85000.0
6 KIM 22 South-Hall 45000.0
7 Jamest On 10000.0
Here is an example that limits the number of rows you want to extract from the table:
##sqlite> SELECT * FROM COMPANY LIMIT 6;
This Will produce the following results: ID -----------------------------------------------------------------------------------19# 1 PAUL 32 California 20000.0
2 Allen 25 Texas 15000.0
3 Teddy 23 NORWAY 20000.0 ## 4 4 Mark 25 Rich-Mond 65000.0
5 David 27 Texas 85000.0
6 Kim 22 South-Hall 45000.0
However, in some cases it may be necessary to start from a specific offset Extract records. The following is an example, starting from the third position to extract 3 records:
##sqlite> SELECT * FROM COMPANY LIMIT 3 OFFSET 2;3 Teddy 23 NORWAY 20000.0 ## 4 4 Mark 25 Rich-Mond 65000.0
5 David 27 Texas 85000.0
6 Kim 22 South-Hall 45000.0
However, in some cases it may be necessary to start from a specific offset Extract records. The following is an example, starting from the third position to extract 3 records:
This will produce the following results:
ID ------ ---------- ----------
3 ‐ David 27 Texas 85000.0
3 ‐ David 27 Texas 85000.0