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

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

Patricia Arquette
Release: 2024-12-05 01:05:14
Original
888 people have browsed it

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

Skipping the First 10 Results in MySQL SELECT Queries

In MySQL, you can skip the first 10 results of a SELECT query using the LIMIT clause. This allows you to focus on specific results within a larger dataset.

Syntax:

SELECT * FROM table_name ORDER BY column_name LIMIT offset, row_count
Copy after login

Parameters:

  • offset: The number of rows to skip before starting the results.
  • row_count: The maximum number of rows to return.

Example:

To skip the first 10 rows and return the next 50 rows from a table named "foo", use the following query:

SELECT * FROM foo ORDER BY id LIMIT 10, 50
Copy after login

Note: Rows in MySQL are numbered starting from 1, so the result 1 refers to the first row.

Alternative Solution:

If you want to skip the first 10 results but return all subsequent results, you can use the following workaround:

  1. Create a subquery that returns the count of rows in the table.
  2. Use the subquery in the main query to calculate the row count to skip.
SELECT * FROM foo
WHERE id > (SELECT COUNT(*) FROM foo) - 10
Copy after login

The above is the detailed content of How to Skip the First 10 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