LIMIT语句可以限制SELECT语句返回的行数。LIMIT使用1个或2个参数,参数必须是非负数的整数。MySQL> select * from dept2 order by 1;
+--------+-------+
| deptno | dname |
+--------+-------+
| 10 | A |
| 20 | B |
| 30 | C |
| 40 | D |
| 50 | E |
| 60 | F |
| 70 | G |
| 80 | H |
| 90 | I |
| 100 | J |
| 110 | K |
| 120 | L |
| 130 | M |
| 140 | N |
| 150 | O |
| 160 | P |
| 170 | Q |
| 180 | R |
| 190 | S |
| 200 | T |
+--------+-------+
20 rows in set (0.03 sec)
--返回第6-15行mysql> select * from dept2 order by 1 limit 5,10;
+--------+-------+
| deptno | dname |
+--------+-------+
| 60 | F |
| 70 | G |
| 80 | H |
| 90 | I |
| 100 | J |
| 110 | K |
| 120 | L |
| 130 | M |
| 140 | N |
| 150 | O |
+--------+-------+
10 rows in set (0.00 sec)
--返回前5行mysql> select * from dept2 order by 1 limit 5;
+--------+-------+
| deptno | dname |
+--------+-------+
| 10 | A |
| 20 | B |
| 30 | C |
| 40 | D |
| 50 | E |
+--------+-------+
5 rows in set (0.00 sec)
mysql> select * from dept2 order by 1 limit 0,5;
+--------+-------+
| deptno | dname |
+--------+-------+
| 10 | A |
| 20 | B |
| 30 | C |
| 40 | D |
| 50 | E |
+--------+-------+
5 rows in set (0.00 sec)
本文标题:MySQL5.7LIMIT语句介绍
浏览路径:
http://cxhlcq.com/article/pggded.html