Usage of limit and offset in SQLite

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.