Home > Database > Mysql Tutorial > How to use limit Mysql query statement

How to use limit Mysql query statement

高洛峰
Release: 2016-10-21 11:18:10
Original
1395 people have browsed it

 In my opinion, limit should be the most frequently used method in mysql. Let’s explain the function of limit and how to use this method correctly.

SELECT * FROM table LIMIT [offset,] rows | rows OFFSET offset
Copy after login

  The 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 parameter 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; // 检索记录行 6-15
Copy after login

   // In order to retrieve all record lines from a certain offset to the end of the recordset, you can specify the second parameter as -1:

 

mysql> SELECT * FROM table LIMIT 95,-1; // 检索记录行 96-last.
Copy after login

   // If only one parameter is given, it means returning the maximum number of record rows:

 

mysql> SELECT * FROM table LIMIT 5; //检索前 5 个记录行
Copy after login

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


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