Home > Database > Mysql Tutorial > body text

What is the use of LIMIT keyword in MySQL query?

王林
Release: 2023-08-27 18:45:02
forward
1135 people have browsed it

What is the use of LIMIT keyword in MySQL query?

#The LIMIT keyword in MySQL can specify the number of records returned in the output. The LIMIT clause limits the number of rows to be returned. It can be understood through 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)
Copy after login

The above result set shows that the table "student_info" has a total of 7 rows.

However, if we only want to get the first 2 rows in the output, then we can use the 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)
Copy after login

The above is the detailed content of What is the use of LIMIT keyword in MySQL query?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template