Limit usage in MySQL

Source: Internet
Author: User

MySQL Limit usage select * from TableName LIMIT [offset,] rows;    1. Select * FROM table limit m,n (show number of bars) where m refers to the index at which the record starts (the index is the first record starting from 0) n means starting with the m+1 and fetching N.    The result is to retrieve records from line m+1 to (M+n), and to fetch N records altogether ex:select * from table name limit 6, 5; Results: Records of rows 7th to 11 were retrieved, and 5 records were taken out.    2. N can be set to-1, and when n is-1, it is retrieved from the M+1 line until the last piece of data is fetched.    Ex:select * FROM table name limit 6,-1; Result: Retrieve all data from line 7th to future.    3, if only given m, then the 1th row from the beginning of the record line to remove m (limit 0,n special case) Ex:select * from the table name limit 6; Result: Retrieves the first 6 rows of records. 4. Search performance Optimization. Select the appropriate statement based on the size of the data: A.offset is small: select * from Doctor limit 10, 10 multiple runs, time remains between 0.0004-0.0005 select * FRO M doctor where ID >= (SELECT ID from Doctor ID limit 10,1) limit 10 runs multiple times, time remains between 0.0005-0.0006, mostly 0.0006 conclusions    : When offset offsets are small, direct use of limit is preferred.    When the B.offset is big. SELECT * FROM Doctor Limit 3000, 10 runs multiple times, time remains around 0.012 select * from Doctor where ID >= (SELECT id from Doctor I    D limit 3000,1) limit 10 runs multiple times, the time remains at about 0.004, only the former 1/3. Conclusion: The larger the offset, the better the latter using the subquery directly.

Limit usage in MySQL

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.