In Sqlite3, the structure of the top syntax is not used, and the Sqlite3 uses limit to achieve such a function. The data in the MyTable table is as follows: Idvalue1&n.
In Sqlite3, the structure of the top syntax is not used, and the Sqlite3 uses limit to achieve such a function.
The data in the MyTable table is as follows:
ID value
1 Hello
2 You
3 You
4 Very Good
5!
The following SQL statement: SELECT * FROM MyTable limit 3; The query results shown are:
1 Hello
2 You
3 You
Equivalent to top 3 in SQL Server, but limit has a more powerful function than top, especially in the paging feature.
The following SQL statement: SELECT * FROM MyTable limit 1, 3;
The results shown are:
2 You
3 You
4 Very Good
The limit m,n means starting from the first record and fetching N Records (the first record is starting from 0, and the 2nd record is starting from 1, one analogy). Therefore, starting from the third record, then m=2, such as starting from the 6th record to fetch data, fetch 10, the SQL statement is as follows: SELECT * FROM MyTable limit 5, 10;
If I want to fetch 11-20 of the Account table data, then: Select * from the person Limit 9 Offset 10;
Represents getting data from the person table, skipping 10 rows, and fetching 9 rows. You can also write select * from the account limit 10,9 and the effect above.
General public test:
sql = "SELECT * from TableName where" + Condition + "ORDER BY" + sort + "limit" + how many records to display + "offset" + how many records to skip;
For example: SELECT * from Contacts limit, offset 20:20 entries from the Contacts table 15 Records selected
This article from "Casket Night Blog" blog, declined reprint!
Usage of limit and offset in SQLite