Get the first 10 rows followed by the syntax to display remaining row records with a single MySQL query

MySQLi DatabaseMySQL

Let us first create a table −

mysql> create table DemoTable
(
   Id int
);
Query OK, 0 rows affected (0.71 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values(100);
Query OK, 1 row affected (0.31 sec)
mysql> insert into DemoTable values(101);
Query OK, 1 row affected (0.26 sec)
mysql> insert into DemoTable values(102);
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable values(103);
Query OK, 1 row affected (0.64 sec)
mysql> insert into DemoTable values(104);
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable values(105);
Query OK, 1 row affected (0.08 sec)
mysql> insert into DemoTable values(106);
Query OK, 1 row affected (0.25 sec)
mysql> insert into DemoTable values(107);
Query OK, 1 row affected (0.44 sec)
mysql> insert into DemoTable values(108);
Query OK, 1 row affected (0.62 sec)
mysql> insert into DemoTable values(109);
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable values(110);
Query OK, 1 row affected (0.31 sec)
mysql> insert into DemoTable values(111);
Query OK, 1 row affected (0.94 sec)
mysql> insert into DemoTable values(112);
Query OK, 1 row affected (0.08 sec)
mysql> insert into DemoTable values(113);
Query OK, 1 row affected (0.35 sec)
mysql> insert into DemoTable values(114);
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable values(115);
Query OK, 1 row affected (0.25 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+------+
| Id   |
+------+
|  100 |
|  101 |
|  102 |
|  103 |
|  104 |
|  105 |
|  106 |
|  107 |
|  108 |
|  109 |
|  110 |
|  111 |
|  112 |
|  113 |
|  114 |
|  115 |
+------+
16 rows in set (0.00 sec)

Following is the query to get the first 10 rows followed by the remaining rows −

mysql> select *from DemoTable LIMIT 999 offset 0;

This will produce the following output −

+------+
| Id   |
+------+
|  100 |
|  101 |
|  102 |
|  103 |
|  104 |
|  105 |
|  106 |
|  107 |
|  108 |
|  109 |
|  110 |
|  111 |
|  112 |
|  113 |
|  114 |
|  115 |
+------+
16 rows in set (0.00 sec)
raja
Published on 01-Oct-2019 08:12:04
Advertisements