Home >Database >Mysql Tutorial >MySQL LIMIT and OFFSET: How Many Rows Are Returned and Where Do They Start?

MySQL LIMIT and OFFSET: How Many Rows Are Returned and Where Do They Start?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-23 02:21:14951browse

MySQL LIMIT and OFFSET: How Many Rows Are Returned and Where Do They Start?

MySQL Limit with Offset: What Results Are Returned?

In MySQL, the LIMIT and OFFSET clauses allow you to retrieve a specific number of rows from a table, starting at a given offset. This article explores how the LIMIT and OFFSET clauses interact to determine which rows are returned from a query.

Consider the following example query:

SELECT column
FROM table
LIMIT 18 OFFSET 8

How Many Results Will Be Returned?

The LIMIT clause specifies that 18 rows will be returned by the query.

Where Will the Results Start?

The OFFSET clause indicates that the results will start at row #9. This is because OFFSET specifies the number of rows to skip before beginning to return results.

To better understand how this works, let's break down the query:

  • The OFFSET clause skips the first 8 rows of the result set.
  • The LIMIT clause then takes the remaining rows and returns the first 18 of them.
  • This means that the results will start from record #9 (after the 8 skipped rows) and finish on record #26 (after the 18 rows returned).

In summary, the query above will return 18 results, starting from record #9 and ending at record #26. For more information, refer to the official MySQL documentation on LIMIT and OFFSET.

The above is the detailed content of MySQL LIMIT and OFFSET: How Many Rows Are Returned and Where Do They Start?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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