Home  >  Article  >  Database  >  What is the use of LIMIT keyword in MySQL query?

What is the use of LIMIT keyword in MySQL query?

王林
王林forward
2023-08-27 18:45:021133browse

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)

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)

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete