Home > Database > Mysql Tutorial > 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
Release: 2023-09-15 10:29:02
forward
1335 people have browsed it

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)
Copy after login

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)
Copy after login

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!

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