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