To skip records in MySQL SELECT, use OFFSET. Let us first create a table−
mysql> create table DemoTable ( Name varchar(40) ); Query OK, 0 rows affected (0.63 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Bob'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+--------+ | Name | +--------+ | Chris | | Robert | | Mike | | Bob | | David | +--------+ 5 rows in set (0.00 sec)
Following is the query to skip first N results −
mysql> select *from DemoTable LIMIT 100 offset 3;
This will produce the following output −
+-------+ | Name | +-------+ | Bob | | David | +-------+ 2 rows in set (0.00 sec)