To skip rows, use LIMIT OFFSET. Let us first create a table −
mysql> create table DemoTable860( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(100) ); Query OK, 0 rows affected (0.73 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable860(Name) values('Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable860(Name) values('Robert'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable860(Name) values('David'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable860(Name) values('Bob'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable860(Name) values('Mike'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable860(Name) values('Sam'); Query OK, 1 row affected (0.07 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable860;
This will produce the following output −
+----+--------+ | Id | Name | +----+--------+ | 1 | Chris | | 2 | Robert | | 3 | David | | 4 | Bob | | 5 | Mike | | 6 | Sam | +----+--------+ 6 rows in set (0.00 sec)
Following is the query to skip rows in MySQL −
mysql> select *from DemoTable860 limit 3 offset 2;
This will produce the following output −
+----+-------+ | Id | Name | +----+-------+ | 3 | David | | 4 | Bob | | 5 | Mike | +----+-------+ 3 rows in set (0.00 sec)