How to select next row pagination in MySQL?

MySQLMySQLi Database

For this, use the LIMIT concept. Let us create a table −

mysql> create table demo40
−> (
−> id int not null auto_increment primary key,
−> name varchar(40)
−> );
Query OK, 0 rows affected (1.73 sec)

Insert some records into the table with the help of insert command −

mysql> insert into demo40(name) values('Chris');
Query OK, 1 row affected (0.23 sec)

mysql> insert into demo40(name) values('David');
Query OK, 1 row affected (0.12 sec)

mysql> insert into demo40(name) values('Mike');
Query OK, 1 row affected (0.10 sec)

mysql> insert into demo40(name) values('Sam');
Query OK, 1 row affected (0.19 sec)

mysql> insert into demo40(name) values('Carol');
Query OK, 1 row affected (0.12 sec)

mysql> insert into demo40(name) values('bob');
Query OK, 1 row affected (0.13 sec)

Display records from the table using select statement −

mysql> select *from demo40;

This will produce the following output −

+----+-------+
| id | name  |
+----+-------+
|  1 | Chris |
|  2 | David |
|  3 | Mike  |
|  4 | Sam   |
|  5 | Carol |
|  6 | bob   |
+----+-------+
6 rows in set (0.00 sec)

Following is the query to select next row pagination in MySQL −

mysql> select *from demo40 limit 4,2;

This will produce the following output −

+----+-------+
| id | name  |
+----+-------+
|  5 | Carol |
|  6 | bob   |
+----+-------+
2 rows in set (0.00 sec)
raja
Published on 19-Nov-2020 12:51:04
Advertisements