{"id":244,"date":"2009-03-02T15:22:00","date_gmt":"2009-03-02T07:22:00","guid":{"rendered":""},"modified":"2013-11-29T14:16:33","modified_gmt":"2013-11-29T06:16:33","slug":"mysql%e4%b8%adlimit%e7%9a%84%e7%94%a8%e6%b3%95","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/244.html","title":{"rendered":"MySQL\u4e2dlimit\u7684\u7528\u6cd5"},"content":{"rendered":"<p>\u5728\u6211\u4eec\u4f7f\u7528\u67e5\u8be2\u8bed\u53e5\u7684\u65f6\u5019\uff0c\u7ecf\u5e38\u8981\u8fd4\u56de\u524d\u51e0\u6761\u6216\u8005\u4e2d\u95f4\u67d0\u51e0\u884c\u6570\u636e\uff0c\u8fd9\u4e2a\u65f6\u5019\u600e\u4e48\u529e\u5462\uff1f\u4e0d\u7528\u62c5\u5fc3\uff0cmysql\u5df2\u7ecf\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u8fd9\u6837\u4e00\u4e2a\u529f\u80fd\u3002<\/p>\n<p>SELECT * FROM table\u00a0\u00a0 LIMIT [offset,] rows | rows OFFSET offset<\/p>\n<p>LIMIT \u5b50\u53e5\u53ef\u4ee5\u88ab\u7528\u4e8e\u5f3a\u5236 SELECT \u8bed\u53e5\u8fd4\u56de\u6307\u5b9a\u7684\u8bb0\u5f55\u6570\u3002LIMIT \u63a5\u53d7\u4e00\u4e2a\u6216\u4e24\u4e2a\u6570\u5b57\u53c2\u6570\u3002\u53c2\u6570\u5fc5\u987b\u662f\u4e00\u4e2a\u6574\u6570\u5e38\u91cf\u3002\u5982\u679c\u7ed9\u5b9a\u4e24\u4e2a\u53c2\u6570\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u6307\u5b9a\u7b2c\u4e00\u4e2a\u8fd4\u56de\u8bb0\u5f55\u884c\u7684\u504f\u79fb\u91cf\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u6307\u5b9a\u8fd4\u56de\u8bb0\u5f55\u884c\u7684\u6700\u5927\u6570\u76ee\u3002\u521d\u59cb\u8bb0\u5f55\u884c\u7684\u504f\u79fb\u91cf\u662f 0(\u800c\u4e0d\u662f 1)\uff1a \u4e3a\u4e86\u4e0e PostgreSQL \u517c\u5bb9\uff0cMySQL \u4e5f\u652f\u6301\u53e5\u6cd5\uff1a LIMIT # OFFSET #\u3002<\/p>\n<p>mysql&gt; SELECT * FROM table LIMIT 5,10; \/\/ \u68c0\u7d22\u8bb0\u5f55\u884c 6-15<\/p>\n<p>\/\/\u4e3a\u4e86\u68c0\u7d22\u4ece\u67d0\u4e00\u4e2a\u504f\u79fb\u91cf\u5230\u8bb0\u5f55\u96c6\u7684\u7ed3\u675f\u6240\u6709\u7684\u8bb0\u5f55\u884c\uff0c\u53ef\u4ee5\u6307\u5b9a\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e3a -1\uff1a<br \/>\nmysql&gt; SELECT * FROM table LIMIT 95,-1; \/\/ \u68c0\u7d22\u8bb0\u5f55\u884c 96-last.<\/p>\n<p>\/\/\u5982\u679c\u53ea\u7ed9\u5b9a\u4e00\u4e2a\u53c2\u6570\uff0c\u5b83\u8868\u793a\u8fd4\u56de\u6700\u5927\u7684\u8bb0\u5f55\u884c\u6570\u76ee\uff1a<br \/>\nmysql&gt; SELECT * FROM table LIMIT 5;\u00a0\u00a0\u00a0\u00a0 \/\/\u68c0\u7d22\u524d 5 \u4e2a\u8bb0\u5f55\u884c<\/p>\n<p>\/\/\u6362\u53e5\u8bdd\u8bf4\uff0cLIMIT n \u7b49\u4ef7\u4e8e LIMIT 0,n\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u6211\u4eec\u4f7f\u7528\u67e5\u8be2\u8bed\u53e5\u7684\u65f6\u5019\uff0c\u7ecf\u5e38\u8981\u8fd4\u56de\u524d\u51e0\u6761\u6216\u8005\u4e2d\u95f4\u67d0\u51e0\u884c\u6570\u636e\uff0c\u8fd9\u4e2a\u65f6\u5019\u600e\u4e48\u529e\u5462\uff1f\u4e0d\u7528\u62c5\u5fc3\uff0cmysql\u5df2\u7ecf\u4e3a\u6211\u4eec [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-244","post","type-post","status-publish","format-standard","hentry","category-code_related"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/244","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=244"}],"version-history":[{"count":1,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/244\/revisions"}],"predecessor-version":[{"id":5316,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/244\/revisions\/5316"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}