MySQL查询中LIMIT关键字有什么用?

MySQL查询中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关键字有什么用?的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!

上一篇 MySQL 数据库名和表名区分大小写吗?
下一篇 我们可以使用 Callable 语句调用函数吗?能用 JDBC 的例子解释一下吗?