How to skip first 10 results in MySQL?


To skip first 10 results, use “limit offset”. The syntax is as follows −

select *from yourTableName limit 10 offset lastValue;

Let us create a table to understand the above syntax. The following is the query to create a table −

mysql> create table SkipFirstTenRecords
   −> (
      −> StudentId int,
      −> StudentName varchar(200)
   −> );
Query OK, 0 rows affected (0.53 sec)

Now you can insert some records in the table with the help of insert command. The query is as follows −

mysql> insert into SkipFirstTenRecords values(100,'John');
Query OK, 1 row affected (0.12 sec)

mysql> insert into SkipFirstTenRecords values(101,'Johnson');
Query OK, 1 row affected (0.14 sec)

mysql> insert into SkipFirstTenRecords values(102,'Carol');
Query OK, 1 row affected (0.10 sec)

mysql> insert into SkipFirstTenRecords values(103,'Smith');
Query OK, 1 row affected (0.32 sec)

mysql> insert into SkipFirstTenRecords values(104,'Bob');
Query OK, 1 row affected (0.14 sec)

mysql> insert into SkipFirstTenRecords values(105,'David');
Query OK, 1 row affected (0.18 sec)

mysql> insert into SkipFirstTenRecords values(106,'Sam');
Query OK, 1 row affected (0.14 sec)

mysql> insert into SkipFirstTenRecords values(107,'Taylor');
Query OK, 1 row affected (0.23 sec)

mysql> insert into SkipFirstTenRecords values(108,'Ramit');
Query OK, 1 row affected (0.16 sec)

mysql> insert into SkipFirstTenRecords values(109,'Belly');
Query OK, 1 row affected (0.18 sec)

mysql> insert into SkipFirstTenRecords values(110,'Aaron ');
Query OK, 1 row affected (0.16 sec)

mysql> insert into SkipFirstTenRecords values(111,'Peter');
Query OK, 1 row affected (0.10 sec)

mysql> insert into SkipFirstTenRecords values(112,'Travis');
Query OK, 1 row affected (0.14 sec)

mysql> insert into SkipFirstTenRecords values(113,'Alex');
Query OK, 1 row affected (0.18 sec)

mysql> insert into SkipFirstTenRecords values(114,'Pat ');
Query OK, 1 row affected (0.11 sec)

Display all records which I have inserted in the table. The query is as follows:

mysql> select *from SkipFirstTenRecords;

The following is the output −

+-----------+-------------+
| StudentId | StudentName |
+-----------+-------------+
|       100 | John        |
|       101 | Johnson     |
|       102 | Carol       |
|       103 | Smith       |
|       104 | Bob         |
|       105 | David       |
|       106 | Sam         |
|       107 | Taylor      |
|       108 | Ramit       |
|       109 | Belly       |
|       110 | Aaron       |
|       111 | Peter       |
|       112 | Travis      |
|       113 | Alex        |
|       114 | Pat         |
+-----------+-------------+
15 rows in set (0.00 sec)

The query to skip first 10 records from the above table is all follows −

mysql> select *from SkipFirstTenRecords limit 10 offset 10;

The following is the output displays only the last 5 records since we skipped the first 10 records −

+-----------+-------------+
| StudentId | StudentName |
+-----------+-------------+
|        110 | Aaron      |
|        111 | Peter      |
|        112 | Travis     |
|        113 | Alex       |
|        114 | Pat        |
+-----------+-------------+
5 rows in set (0.00 sec)

Updated on: 25-Jun-2020

818 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements