3 ways to skip first 10 results

This article will be looking into how to skip the first 10 results from a query result and return the remaining rows using different ways.

Table of Contents:

Let us get started by preparing the sample data. We will be creating a table, sale_details, followed by inserting rows into it.

#create the table sale_details
CREATE TABLE sale_details (
    id INT ,
	sale_person_id VARCHAR(255) ,
    sale_person_name VARCHAR(255),
    no_products_sold INT,
    sales_department VARCHAR(255)
);
# insert rows to sale_details
 INSERT INTO sale_details (id,sale_person_id,sale_person_name,no_products_sold,sales_department) 
 VALUES(1,"sd1","Henry",2000,"Kitchen Essentials"),
 (2,"sd1","Henry",5000,"Apparels"),
 (3,"sd1","Henry",40,"Medicines"),
 (4,"sd2","Richa",3000,"Kitchen Essentials"),
 (5,"sd2","Richa",500,"Apparels"),
 (6,"sd2","Richa",50,"Medicines"),
 (7,"sd3","Ved",100,"Kitchen Essentials"),
 (8,"sd3","Ved",150,"Apparels"),
 (9,"sd3","Ved",1000,"Medicines"),
 (10,"sd4","George",600,"Kitchen Essentials"),
 (11,"sd4","George",1200,"Apparels"),
 (12,"sd4","George",200,"Medicines"),
  (13,"sd5","Alexendra",487,"Kitchen Essentials"),
 (14,"sd5","Alexendra",570,"Apparels"),
 (15,"sd5","Alexendra",510,"Medicines"),
 (16,"sd6","Gustav",3000,"Kitchen Essentials"),
 (17,"sd6","Gustav",100,"Apparels"),
 (18,"sd6","Gustav",150,"Medicines");

Action Output:-

image_1

Create table and inserts are successful, to view the snapshot of the table execute:

SELECT * FROM TABLE sale_details; 

Output:-

image_2

The table sale_details has 18 rows.

Skip first 10 results from MYSQL query using id key

The below query gets only those results that have an id value greater than 10.

SELECT * FROM sale_details WHERE id >10;

Output:-

image_3

Skip first 10 results from MYSQL query using subquery

The below query gets only the results, excluding the id values returned by the subquery result.

SELECT * FROM sale_details WHERE ID NOT IN (select id FROM sale_details WHERE id BETWEEN 1 and 10);

Output:-

image_4

Skip first 10 results from MYSQL query using LIMIT and OFFSET

The LIMIT clause in MySQL is used to get the limited number of rows in the SELECT query results. OFFSET is passed as a numeric argument that specifies the offset of the first row to return.

Read in details about: LIMIT with OFFSET in MYSQL

The below query will skip the first 10 rows as the OFFSET value passed with the LIMIT clause is 10. This offset skips the specified number of table records. Note that the LIMIT value passed is 10 as well. That will return only 10 records at a time as a query result.

  SELECT * FROM sale_details LIMIT 10, 10;

Output:-

image_5

The output in image_5 shows 8 rows as there are only 18 rows in the table.

If we do not want to apply any LIMIT to the results, we will have to specify the maximum value of unsigned BIGINT (18446744073709551615) as the limit argument (limit argument is mandatory). Observe the below query.

SELECT * FROM sale_details LIMIT 18446744073709551615 OFFSET 10;

Output:-

image_6

READ MORE:

We hope this article helped you with how to skip first 10 results from the MySQL query. Good Luck!!!

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top