Home  >  Article  >  Database  >  How do we specify the number of records to return in MySQL output?

How do we specify the number of records to return in MySQL output?

WBOY
WBOYforward
2023-09-15 10:29:021297browse

How do we specify the number of records to return in MySQL output?

We can specify the number of records returned in the output by adding the LIMIT clause to the MySQL query. The LIMIT clause limits 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 above query shows that the table rates list has a total of 5 rows. Now if we want to get only the first 3 rows from the output then we can use LIMIT clause as shown below -

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)

The above is the detailed content of How do we specify the number of records to return in MySQL output?. 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
Previous article:How to use Go with MySQL?Next article:How to use Go with MySQL?