
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to write a MySQL query to select first 10 records?
To select first 10 records, we can first order the records in ascending or descending order. With that, use LIMIT 10 to get only 10 records −
select *from (select *from yourTableName ORDER BY yourColumnName ASC LIMIT 10)anyAliasName ORDER BY yourColumnName DESC;
Let us first create a table −
mysql> create table DemoTable683(Page int); Query OK, 0 rows affected (0.83 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable683 values(100); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable683 values(101); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable683 values(102); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable683 values(103); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable683 values(104); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable683 values(105); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable683 values(106); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable683 values(107); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable683 values(108); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable683 values(109); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable683 values(110); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable683 values(111); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable683 values(112); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable683 values(113); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable683 values(114); Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable683;
This will produce the following output −
+------+ | Page | +------+ | 100 | | 101 | | 102 | | 103 | | 104 | | 105 | | 106 | | 107 | | 108 | | 109 | | 110 | | 111 | | 112 | | 113 | | 114 | +------+ 15 rows in set (0.00 sec)
Following is the query to select first 10 records in MySQL −
mysql> select *from (select *from DemoTable683 ORDER BY Page ASC LIMIT 10)tbl ORDER BY Page DESC;
This will produce the following output −
+------+ | Page | +------+ | 109 | | 108 | | 107 | | 106 | | 105 | | 104 | | 103 | | 102 | | 101 | | 100 | +------+ 10 rows in set (0.00 sec)
- Related Articles
- MySQL query to select top 10 records?
- MySQL query to select bottom n records
- MySQL query to select records with a particular date?
- How to select first 10 elements from a MySQL database?
- MySQL query to select records beginning from a specific id
- MySQL query to select records with a particular date and time?
- Select first word in a MySQL query?
- MySQL query to select records approaching in next 12 hours?
- MySQL SELECT query to return records with specific month and year
- Get the first 10 rows followed by the syntax to display remaining row records with a single MySQL query
- MongoDB Query to select records having a given key?
- How to select all records that are 10 minutes within current timestamp in MySQL?
- MySQL query to select rows except first row in descending order?
- MySQL query to select everything to left of last space in a column with name records
- MySQL query to select records from a table on the basis of a particular month number?

Advertisements