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 such a feature.
SELECT * FROM table LIMIT [offset,] rows | Rows Offset Offset
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 first return
The offset of the record row, and the second parameter specifies the maximum number of rows to return records. The offset of the initial record line is 0 (not 1): MySQL also supports syntax for PostgreSQL compatibility: LIMIT #
OFFSET #.
Mysql> SELECT * FROM table LIMIT 5, 10; Retrieving record lines
Section
6 rows to 15th row of data
In order to retrieve all the 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; Retrieves the record line 96-last.
If only one parameter is given, it indicates 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.
A detailed description of limit usage in MySQL (data paging is often used)