In MySQL, LIMIT is a very useful keyword used to limit the number of query results. By using LIMIT, we can specify the number of rows to be returned from the query results, which is useful for paginated queries and controlling the result set size. This article will introduce the usage of LIMIT in detail and provide corresponding PHP code examples.
Basic usage of LIMIT
The basic syntax of the LIMIT statement is as follows:
SELECT column1, column2, ...
FROM table
LIMIT offset, count;
Among them, offset represents the number of rows returned from the starting position of the query result, and count represents the number of rows returned. Suppose we have a users
table named with two columns: id
and . name
The following example will return 5 rows of results starting at row 3:
<?php
$servername = "localhost";
$username = "your_username";