{"id":5771,"date":"2024-11-14T10:27:33","date_gmt":"2024-11-14T02:27:33","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5771\/"},"modified":"2024-11-14T10:27:33","modified_gmt":"2024-11-14T02:27:33","slug":"mysql-limit%e4%bb%80%e4%b9%88%e6%84%8f%e6%80%9d","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5771\/","title":{"rendered":"mysql\u00a0limit\u4ec0\u4e48\u610f\u601d"},"content":{"rendered":"<blockquote><p>\n  mysql \u7684 limit \u5b50\u53e5\u9650\u5236 select \u67e5\u8be2\u8fd4\u56de\u7684\u884c\u6570\uff1a\u6307\u5b9a\u504f\u79fb\u91cf\uff0c\u4ece\u8fd4\u56de\u7684\u6570\u636e\u96c6\u4e2d\u5f00\u59cb\u7684\u884c\u6570\u3002\u6307\u5b9a\u884c\u6570\uff0c\u8981\u68c0\u7d22\u7684\u884c\u6570\u3002\u5fc5\u987b\u51fa\u73b0\u5728 order by \u5b50\u53e5\uff08\u5982\u679c\u5b58\u5728\uff09\u4e4b\u540e\u3002\u53c2\u6570\u5fc5\u987b\u662f\u6574\u6570\uff0c\u672a\u6307\u5b9a\u504f\u79fb\u91cf\u5219\u9ed8\u8ba4\u4e3a 0\u3002row_count \u548c offset \u90fd\u4e3a 0 \u65f6\u8fd4\u56de\u7a7a\u96c6\u3002\u53ef\u4e0e\u5176\u4ed6\u5b50\u53e5\u7ed3\u5408\u4f7f\u7528\u3002\u4f18\u5316\u67e5\u8be2\uff0c\u9650\u5236\u8fd4\u56de\u6570\u636e\u91cf\uff0c\u63d0\u9ad8\u6027\u80fd\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/02\/2024060201064774514.jpg\" class=\"aligncenter\" title=\"mysql\u00a0limit\u4ec0\u4e48\u610f\u601d\u63d2\u56fe\" alt=\"mysql\u00a0limit\u4ec0\u4e48\u610f\u601d\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL LIMIT \u7528\u6cd5\u8be6\u89e3<\/strong><\/p>\n<p><strong>\u4ec0\u4e48\u662f LIMIT\uff1f<\/strong><\/p>\n<p>MySQL \u4e2d\u7684 LIMIT \u5b50\u53e5\u7528\u4e8e\u9650\u5236 SELECT \u67e5\u8be2\u8fd4\u56de\u7684\u884c\u6570\u3002\u5b83\u5141\u8bb8\u60a8\u6307\u5b9a\u4ece\u8fd4\u56de\u6570\u636e\u96c6\u4e2d\u5f00\u59cb\u7684\u884c\u7684\u504f\u79fb\u91cf\u4ee5\u53ca\u8981\u68c0\u7d22\u7684\u884c\u6570\u3002<\/p>\n<p><strong>\u8bed\u6cd5<\/strong><\/p>\n<pre>SELECT ...\nLIMIT row_count\nOFFSET offset<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> <strong>row_count\uff1a<\/strong>\u8981\u8fd4\u56de\u7684\u884c\u6570\u3002<\/li>\n<li> <strong>offset\uff1a<\/strong>\u4ece\u8fd4\u56de\u7684\u6570\u636e\u96c6\u4e2d\u5f00\u59cb\u7684\u884c\u7684\u504f\u79fb\u91cf\uff08\u53ef\u9009\uff09\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u8981\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u524d 10 \u884c\u7684\u8868 users \u7684\u7ed3\u679c\u96c6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8be2\uff1a<\/p>\n<pre>SELECT * FROM users\nLIMIT 10;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8981\u4ece\u7b2c 5 \u884c\u5f00\u59cb\u8fd4\u56de 15 \u884c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8be2\uff1a<\/p>\n<pre>SELECT * FROM users\nLIMIT 15 OFFSET 5;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<ul>\n<li>LIMIT \u5b50\u53e5\u5fc5\u987b\u51fa\u73b0\u5728 ORDER BY \u5b50\u53e5\u4e4b\u540e\uff08\u5982\u679c\u5b58\u5728\uff09\u3002<\/li>\n<li>row_count \u548c offset \u53c2\u6570\u5fc5\u987b\u662f\u6574\u6570\u3002<\/li>\n<li>\u5982\u679c\u672a\u6307\u5b9a\u504f\u79fb\u91cf\uff0c\u5219\u5176\u9ed8\u8ba4\u4e3a 0\uff0c\u5373\u4ece\u7ed3\u679c\u96c6\u7684\u5f00\u5934\u5f00\u59cb\u3002<\/li>\n<li>\u5982\u679c row_count \u548c offset \u90fd\u4e3a 0\uff0c\u5219\u67e5\u8be2\u5c06\u8fd4\u56de\u7a7a\u96c6\u3002<\/li>\n<li>LIMIT \u5b50\u53e5\u53ef\u4ee5\u4e0e\u5176\u4ed6\u5b50\u53e5\uff08\u4f8b\u5982 WHERE \u548c GROUP BY\uff09\u7ed3\u5408\u4f7f\u7528\u3002<\/li>\n<li>LIMIT \u5b50\u53e5\u7528\u4e8e\u4f18\u5316\u67e5\u8be2\u5e76\u9650\u5236\u8fd4\u56de\u7684\u6570\u636e\u91cf\uff0c\u4ece\u800c\u63d0\u9ad8\u6027\u80fd\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f&nbsp;limit\u4ec0\u4e48\u610f\u601d\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>mysql \u7684 limit \u5b50\u53e5\u9650\u5236 select \u67e5\u8be2\u8fd4\u56de\u7684\u884c\u6570\uff1a\u6307\u5b9a\u504f\u79fb\u91cf\uff0c\u4ece\u8fd4\u56de\u7684\u6570\u636e\u96c6\u4e2d\u5f00\u59cb\u7684\u884c\u6570\u3002\u6307\u5b9a\u884c\u6570\uff0c\u8981\u68c0\u7d22\u7684\u884c\u6570\u3002\u5fc5\u987b\u51fa\u73b0\u5728 order by \u5b50\u53e5\uff08\u5982\u679c\u5b58\u5728\uff09\u4e4b\u540e\u3002\u53c2\u6570\u5fc5\u987b\u662f\u6574\u6570\uff0c\u672a\u6307\u5b9a\u504f\u79fb\u91cf\u5219\u9ed8\u8ba4\u4e3a 0\u3002row_count \u548c offset \u90fd\u4e3a 0 \u65f6\u8fd4\u56de\u7a7a\u96c6\u3002\u53ef\u4e0e\u5176\u4ed6\u5b50\u53e5\u7ed3\u5408\u4f7f\u7528\u3002\u4f18\u5316\u67e5\u8be2\uff0c\u9650\u5236\u8fd4\u56de\u6570\u636e\u91cf\uff0c\u63d0\u9ad8\u6027\u80fd\u3002 MySQL LIMIT \u7528\u6cd5\u8be6\u89e3 \u4ec0\u4e48\u662f LIMIT\uff1f MySQL \u4e2d\u7684 LIMIT \u5b50\u53e5\u7528\u4e8e\u9650\u5236 SELECT \u67e5\u8be2\u8fd4\u56de\u7684\u884c\u6570\u3002\u5b83\u5141\u8bb8\u60a8\u6307\u5b9a\u4ece\u8fd4\u56de\u6570\u636e\u96c6\u4e2d\u5f00\u59cb\u7684\u884c\u7684\u504f\u79fb\u91cf\u4ee5\u53ca\u8981\u68c0\u7d22\u7684\u884c\u6570\u3002 \u8bed\u6cd5 SELECT &#8230; LIMIT row_count OFFSET offset \u767b\u5f55\u540e\u590d\u5236 row_count\uff1a\u8981\u8fd4\u56de\u7684\u884c\u6570\u3002 offset\uff1a\u4ece\u8fd4\u56de\u7684\u6570\u636e\u96c6\u4e2d\u5f00\u59cb\u7684\u884c\u7684\u504f\u79fb\u91cf\uff08\u53ef\u9009\uff09\u3002 \u793a\u4f8b \u8981\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u524d 10 \u884c\u7684\u8868 users \u7684\u7ed3\u679c\u96c6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8be2\uff1a SELECT * FROM users LIMIT 10; \u767b\u5f55\u540e\u590d\u5236 \u8981\u4ece\u7b2c 5 \u884c\u5f00\u59cb\u8fd4\u56de 15 \u884c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8be2\uff1a SELECT [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5771","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5771","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5771"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5771\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5771"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}