Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use limit in MySQL database

Shulou Source: shulou.com Published: 2022-06-03 11:01:05 10月02日 Update

This article will explain in detail how to use limit in the MySQL database. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

In my opinion, limit is probably the most frequently used method in mysql.

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

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. If 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 row is 0 instead of

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.

This is the end of the article on "how to use limit in MySQL database". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Parameters retrieval article offset data database maximum two number more good practical content syntax clause constant in other words numbers integers articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Microsoft MariaDB Shulou Technology MySQL