Home > Database > Mysql Tutorial > How to Skip the First N Results in a MySQL SELECT Query?

How to Skip the First N Results in a MySQL SELECT Query?

Patricia Arquette
Release: 2024-11-29 21:21:09
Original
988 people have browsed it

How to Skip the First N Results in a MySQL SELECT Query?

Skipping Results in MySQL: Understanding LIMIT

In MySQL, the LIMIT clause is a powerful tool to control the number of results returned by a query. One common scenario is the need to skip an initial set of results and start displaying from a specific position.

Problem:

How can we skip the first 10 results in a MySQL SELECT query?

Answer:

To skip the first 10 results, you can utilize the LIMIT clause with two parameters. The first parameter represents the starting position (0-based), and the second parameter indicates the number of records to return.

For instance, to return results starting from the 11th row (skipping the first 10), you would use the following query:

SELECT * FROM foo LIMIT 10, 50
Copy after login

In this query, "foo" represents the table name. The first parameter, 10, tells MySQL to start fetching results from the 11th row. The second parameter, 50, specifies that a total of 50 rows should be returned, resulting in rows 11-60.

Note: It's important to remember that row numbers in MySQL start from 0. So, to skip the first row, you would use a starting position of 1.

The above is the detailed content of How to Skip the First N Results in a MySQL SELECT Query?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template