
- 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
MySQL query to select top 10 records?
To select top 10 records, use LIMIT in MySQL. Let us first create a table −
mysql> create table DemoTable -> ( -> PageNumber text -> ); Query OK, 0 rows affected (2.50 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Page-1'); Query OK, 1 row affected (0.46 sec) mysql> insert into DemoTable values('Page-2'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('Page-3'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values('Page-4'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Page-5'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values('Page-6'); Query OK, 1 row affected (1.12 sec) mysql> insert into DemoTable values('Page-7'); Query OK, 1 row affected (1.21 sec) mysql> insert into DemoTable values('Page-8'); Query OK, 1 row affected (1.15 sec) mysql> insert into DemoTable values('Page-9'); Query OK, 1 row affected (0.89 sec) mysql> insert into DemoTable values('Page-10'); Query OK, 1 row affected (1.20 sec) mysql> insert into DemoTable values('Page-11'); Query OK, 1 row affected (0.86 sec) mysql> insert into DemoTable values('Page-12'); Query OK, 1 row affected (0.39 sec) mysql> insert into DemoTable values('Page-13'); Query OK, 1 row affected (0.39 sec) mysql> insert into DemoTable values('Page-14'); Query OK, 1 row affected (0.47 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+------------+ | PageNumber | +------------+ | Page-1 | | Page-2 | | Page-3 | | Page-4 | | Page-5 | | Page-6 | | Page-7 | | Page-8 | | Page-9 | | Page-10 | | Page-11 | | Page-12 | | Page-13 | | Page-14 | +------------+ 14 rows in set (0.00 sec)
Following is the query to select top 10 records −
mysql> select *from DemoTable limit 0,10;
Output
This will produce the following output −
+------------+ | PageNumber | +------------+ | Page-1 | | Page-2 | | Page-3 | | Page-4 | | Page-5 | | Page-6 | | Page-7 | | Page-8 | | Page-9 | | Page-10 | +------------+ 10 rows in set (0.00 sec)
- Related Articles
- How to write a MySQL query to select first 10 records?
- MySQL query to select bottom n records
- MySQL query to select top n rows efficiently?
- MySQL query to select records with a particular date?
- Does SELECT TOP command exist in MySQL to select limited number of records?
- MySQL query to select records beginning from a specific id
- MySQL query to select records approaching in next 12 hours?
- MySQL query to select records with a particular date and time?
- MySQL SELECT query to return records with specific month and year
- MySQL Query to set currency records
- 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 everything to left of last space in a column with name records
- MySQL query to insert multiple records quickly
- MySQL query to select records from a table on the basis of a particular month number?

Advertisements