English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
SQLite LIMIT
The clause is used to limit the amount of data returned by the SELECT statement.
The following is the basic syntax of a SELECT statement with the LIMIT clause.
SELECT column1, column2, columnN FROM table_nameLIMIT [no of rows]
The following is the syntax when using the LIMIT clause with the OFFSET clause.
SELECT column1, column2, columnN FROM table_nameLIMIT [no of rows] OFFSET [row num]
As shown in the previous example, the SQLite engine will return rows starting from the next row to the given OFFSET.
Consider the COMPANY table with the following records-
ID NAME AGE ADDRESS SALARY ---------- ---------- ---------- ---------- ---------- 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 James 24 Houston 10000.0
Here is an example that limits the rows in the table based on the number of rows to be retrieved from the table.
sqlite> SELECT * FROM COMPANY LIMIT 6;
This will produce the following result.
ID NAME AGE ADDRESS SALARY ---------- ---------- ---------- ---------- ---------- 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
However, in some cases, you may need to retrieve a set of records from a specific offset. Below is an example that starts retrieving from the third position.3records.
sqlite> SELECT * FROM COMPANY LIMIT 3 OFFSET 2;
This will produce the following result.
ID NAME AGE ADDRESS SALARY ---------- ---------- ---------- ---------- ---------- 3 Teddy 23 Norway 20000.0 4 Mark 25 Rich-Mond 65000.0 5 David 27 Texas 85000.0