
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- How can we get the sorted MySQL output?
- How can we divide the result set returned by MySQL into groups?
- How can we sort MySQL output in descending order?
- How can we sort MySQL output in ascending order?
- 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 MySQL COALESCE() function be used with MySQL SUM() function to customize the output?
- How can we use the output of LTRIM() and RTRIM() functions to update MySQL table?
- How can we get an idea about the server performance from the output of MySQL?
- 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 we fetch all the records from a particular MySQL table?
- GROUP BY the number of rows returned by GROUP BY in MySQL?
- How can we display all the records from MySQL table with the help of PHP script?
- How can we insert values into a table with the help of MySQL self-computed output?
Advertisements