Get the App
SLTechnology News&Howtos  ›  Database  › 

How to use limit in Mysql

Shulou Source: shulou.com Published: 2022-05-31 19:25:18 10月03日 Update

This article is to share with you about how to use limit in Mysql. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

The LIMIT clause can be used to force the SELECT statement to return a 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 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 line is 0 (not 1): for compatibility with PostgreSQL, MySQL also supports syntax: LIMIT # OFFSET #.

Mysql > SELECT * FROM table LIMIT 510; / / retrieve record lines 6-15

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

Mysql > SELECT * FROM table LIMIT 95 96-last; / / search the record line.

/ / if only one parameter is given, it represents the maximum number of record rows returned:

Mysql > SELECT * FROM table LIMIT 5; / / retrieve the first five record rows

/ / in other words, LIMIT n is equivalent to LIMIT 0penny n.

Notice the difference between limit 10 and limit 9.

The above is how to use limit in Mysql. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Tags: Parameters retrieval offset maximum two number more knowledge article different practical syntax clause that is work will constant in other words numbers integers articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Xiaomi Apple Redmi Shulou Information