MySQL中的LIMIT关键字可以指定输出中返回的记录数。 LIMIT 子句限制要返回的行数。可以通过以下示例来理解 -
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)
上面的结果集显示表“student_info”总共有 7 行。
但是,如果我们只想在输出中获取前 2 行,那么我们可以使用 LIMIT关键字后跟 2,如下 -
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)
以上是MySQL查询中LIMIT关键字有什么用?的详细内容。更多信息请关注PHP中文网其他相关文章!