sqlite
Database; use; embedded relational database
limit
英[?l?m?t]美[?l?m?t]
n.limit;limit;limit,limit
vt.limit,limit
SQLite Limit function syntax
Function:SQLite's LIMIT clause is used to limit the amount of data returned by the SELECT statement.
Syntax: 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]
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]
The SQLite engine will return all rows starting from the next row up to the given OFFSET, as shown in the last example below.
SQLite Limit function example
COMPANY 表有以下記錄: 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 下面是一個實例,它限制了您想要從表中提取的行數: sqlite> SELECT * FROM COMPANY LIMIT 6; 這將產生以下結果: 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 但是,在某些情況下,可能需要從一個特定的偏移開始提取記錄。下面是一個實例,從第三位開始提取 3 個記錄: sqlite> SELECT * FROM COMPANY LIMIT 3 OFFSET 2; 這將產生以下結果: ID NAME AGE ADDRESS SALARY ---------- ---------- ---------- ---------- ---------- 3 Teddy 23 Norway 20000.0 4 Mark 25 Rich-Mond 65000.0 5 David 27 Texas 85000.0