Home  >  Article  >  Backend Development  >  Detailed explanation and precautions for usage of limit in Mysql_PHP tutorial

Detailed explanation and precautions for usage of limit in Mysql_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:52:47717browse

When we use query statements, we often need to return the first few rows of data or the middle rows of data. What should we do at this time? Don't worry,
mysql already provides us with such a function.
SELECT * FROM table LIMIT [offset,] rows | rows OFFSET offset

LIMIT clause can be used to force the SELECT statement to return the specified number of records. LIMIT accepts one or two numeric arguments. The argument must
be an integer constant. If two parameters are given, the first parameter specifies the offset of the first returned record row, and the second parameter specifies the maximum number of returned
record rows. The offset of the initial record row is 0 (instead of 1): For compatibility with PostgreSQL, MySQL also supports the syntax: LIMIT # OFFSET #.


mysql> SELECT * FROM table LIMIT 5,10; //Retrieve record rows 6-15

//In order to retrieve all records from a certain offset to the end of the record set For record lines, you can specify the second parameter as -1:
mysql> SELECT * FROM table LIMIT 95,-1; // Retrieve record lines 96-last.

//If only given A parameter that represents the maximum number of record rows returned:
mysql> SELECT * FROM table LIMIT 5; //Retrieve the first 5 record rows

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

http://www.bkjia.com/PHPjc/318855.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/318855.htmlTechArticleWhen we use query statements, we often need to return the first few rows of data or the middle rows of data. What should we do at this time? What to do? Don't worry, mysql has provided us with such a function...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn