MySQL Limit optimization method and detailed description (1/3)

Source: Internet
Author: User
Tags mysql tutorial first row

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 be an integer constant. Given two parameters, the first parameter specifies the offset of the first row to return the record, and the second parameter specifies the maximum number of rows to be returned. The initial record line offset is 0 (instead of 1): For compatibility with PostgreSQL, the MySQL tutorial also supports syntax: 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.

Note the differences between limit 10 and limit 9,1:

For example:

1.


SELECT * FROM Cyclopedia where id>= (
Select Max (ID) from (
Select ID from Cyclopedia ORDER by ID limit 90001
) as TMP
) limit 100;


2.

SELECT * FROM Cyclopedia where id>= (
Select Max (ID) from (
Select ID from Cyclopedia ORDER by ID limit 90000,1
) as TMP
) limit 100;

Home 1 2 3 last
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.