The usage method of limit in MySQL and the _php skills of attention

Source: Internet
Author: User
When we use the query statement, often to return the first few or the middle of a few lines of data, this time how to do? Do not worry
MySQL has provided us with such a feature.
SELECT * FROM table LIMIT [offset,] rows | Rows Offset Offset

The LIMIT clause can be used to force a SELECT statement to return the specified number of records. LIMIT accepts one or two numeric parameters. Parameter must
is an integer constant. Given two arguments, the first parameter specifies the offset of the first row to return the record, and the second parameter specifies the return
Maximum number of record rows. The offset of the initial record line is 0 (instead of 1): For compatibility with PostgreSQL, MySQL also supports sentences
fa: LIMIT # OFFSET #.


Mysql> SELECT * FROM table LIMIT 5, 10; Retrieve Record Row 6-15

To retrieve all row rows from an offset to the end of a recordset, you can specify a second argument of-1:
Mysql> SELECT * from table LIMIT 95,-1; Retrieves the record row 96-last.

If only one argument is given, it represents the maximum number of record rows returned:
Mysql> SELECT * from table LIMIT 5; Retrieve the first 5 rows of records

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

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.