我们如何指定要在MySQL输出中返回的记录数?
我们可以通过在MySQL查询中添加LIMIT子句来指定要在输出中返回的记录数。LIMIT子句限制要返回的行数。请看以下示例-
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)
上面的查询显示表速率列表总共有5行。现在,如果我们只想获取输出中的前三行,则可以使用LIMIT子句,如下所示:
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)