
- 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 can we specify the number of records to be returned in MySQL output?
We can specify the number of records to be returned in output by adding a LIMIT clause in MySQL query. LIMIT clause restricts the number of rows to be returned. Consider the following example −
mysql> Select * from ratelist ORDER BY Price; +----+------+-------+ | Sr | Item | Price | +----+------+-------+ | 5 | T | 250 | | 1 | A | 502 | | 2 | B | 630 | | 4 | h | 850 | | 3 | C | 1005 | +----+------+-------+ 5 rows in set (0.00 sec)
The query above shows that the table rate list is having a total of 5 rows. Now if we want to get only the top 3 rows in output then we can use LIMIT clause as follows −
mysql> Select * from ratelist ORDER BY Price LIMIT 3; +----+------+-------+ | Sr | Item | Price | +----+------+-------+ | 5 | T | 250 | | 1 | A | 502 | | 2 | B | 630 | +----+------+-------+ 3 rows in set (0.00 sec)
- Related Articles
- How can we get the sorted MySQL output?
- How can we sort MySQL output in descending order?
- How can we sort MySQL output in ascending order?
- How can we divide the result set returned by MySQL into groups?
- How can we specify default values in MySQL INSERT statement?
- How can we apply filtering criteria at group levels of the result set returned by MySQL?
- How can we use the output of LTRIM() and RTRIM() functions to update MySQL table?
- How can we pass an empty string as a parameter to BIT_LENGTH() function and what would be returned by MySQL?
- How can we get the summary output of a column in MySQL result set itself?
- How can MySQL COALESCE() function be used with MySQL SUM() function to customize the output?
- How can we get an idea about the server performance from the output of MySQL?
- How can we fetch all the records from a particular MySQL table?
- In MySQL, how we can get the total value by category in one output row?
- How can we fetch alternate even-numbered records from MySQL table?
- How can we fetch alternate odd numbered records from MySQL table?

Advertisements