
- 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
What is the use of the LIMIT keyword in MySQL query?
LIMIT keyword in MySQL can specify the number of records to be returned in the output. LIMIT clause restricts the number of rows to be returned. It can be understood with the help of the following example −
Example
mysql> Select * from Student_info; +------+---------+------------+------------+ | id | Name | Address | Subject | +------+---------+------------+------------+ | 101 | YashPal | Amritsar | History | | 105 | Gaurav | Chandigarh | Literature | | 125 | Raman | Shimla | Computers | | 130 | Ram | Jhansi | Computers | | 132 | Shyam | Chandigarh | Economics | | 133 | Mohan | Delhi | Computers | | 150 | Saurabh | NULL | Literature | +------+---------+------------+------------+ 7 rows in set (0.00 sec)
The above result set shows that the table ‘student_info’ is having totaled 7 rows.
But, if we want to get only the top 2 rows in output then we can use LIMIT keyword followed by 2 as follows −
mysql> Select * from Student_info LIMIT 2; +------+---------+------------+------------+ | id | Name | Address | Subject | +------+---------+------------+------------+ | 101 | YashPal | Amritsar | History | | 105 | Gaurav | Chandigarh | Literature | +------+---------+------------+------------+ 2 rows in set (0.00 sec)
- Related Questions & Answers
- What is the limit of auto_increment (integer) in MySQL?
- What is the use of MySQL BINARY keyword while performing string comparison?
- Is it possible to use UPDATE query with LIMIT in MySQL?
- What is the use of "is" keyword in C#?
- What is the use of underscore keyword in Java 9?
- What is the use of ‘new’ keyword in C#?
- The MySQL EXPLAIN keyword executes the query or just explains the query?
- What is the use of NCHAR in MySQL?
- What is the use of MySQL FROM_UNIXTIME() function?
- What is the use of MySQL GET_FORMAT() function?
- What is the use of MySQL LAST_INSERT_ID() function?
- What is the use of MySQL CONCAT_WS() function?
- What is the use of MySQL TRUNCATE() function?
- What is the use of MySQL UNHEX() function?
- What is the use of MySQL SUBSTRING_INDEX() function?
Advertisements