Home > Backend Development > PHP Tutorial > lunalimited Detailed explanation and precautions for usage of limit in Mysql

lunalimited Detailed explanation and precautions for usage of limit in Mysql

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-29 08:37:54
Original
1755 people have browsed it

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 a 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 record rows returned. 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 record rows from a certain offset to the end of the record set, you can specify the second parameter as -1 :
mysql> SELECT * FROM table LIMIT 95,-1; //Retrieve record rows 96-last.
//If only one parameter is given, it means returning the maximum number of record rows:
mysql> SELECT * FROM table LIMIT 5; //Retrieve the first 5 record lines
//In other words, LIMIT n is equivalent to LIMIT 0,n.
The above introduces the detailed usage and precautions of lunalimited in Mysql, including the content of lunalimited. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template