Syntax error How can we specify the number of records to be returned in MySQL output?

How can we specify the number of records to be returned in MySQL output?



We can specify the number of records to be returned in output by adding a LIMIT clause in MySQL query. LIMIT clause restricts 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 query above shows that the table rate list is having a total of 5 rows. Now if we want to get only the top 3 rows in output then we can use LIMIT clause as follows −

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)
Updated on: 2020-06-22T11:01:04+05:30

200 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements