Use of the limit of SQLite

Source: Internet
Author: User

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

SELECT * FROM table LIMIT [offset,] rows | rows offset Offset

When we use query statements, we often have to return the first few or the middle of a few rows of data, this time what to do? Don't worry, MySQL has provided us with one of these features.

The LIMIT clause can be used to force the SELECT statement to return the specified number of records. LIMIT accepts one or two numeric parameters. parameter must be an integer constant. Given two parameters, the first parameter specifies the offset of the first return record row, and the second parameter specifies the maximum number of rows to return records. The initial record line offset is 0 (not 1): MySQL also supports syntax: LIMIT # offset # In order to be compatible with PostgreSQL.

mysql> SELECT * FROM table LIMIT 5, 10;//retrieve record line 6-15// in order to retrieve all record rows from an offset to the end of the recordset, you can specify a second parameter of -1:mysql> SELECT * from table LIMIT 95,-1;//retrieve record line 96-last. //If only one parameter is given, it represents the maximum number of record rows returned: mysql> SELECT * from table LIMIT 5; Retrieving the first 5 rows of records

In other words, limit n is equivalent to limit 0,n.

Use of the limit of 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.