{"id":200783,"date":"2025-05-06T11:21:18","date_gmt":"2025-05-06T03:21:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200783\/"},"modified":"2025-05-06T11:21:18","modified_gmt":"2025-05-06T03:21:18","slug":"%e5%9c%a8-mysql-%e4%b8%ad%ef%bc%8c%e4%b8%ba%e4%bb%80%e4%b9%88%e4%b8%8d%e8%83%bd%e5%9c%a8%e5%ad%90%e6%9f%a5%e8%af%a2%e7%9a%84-from-%e5%ad%90%e5%8f%a5%e4%b8%ad%e6%9b%b4%e6%96%b0%e5%bd%93%e5%89%8d","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200783\/","title":{"rendered":"\u5728 MySQL \u4e2d\uff0c\u4e3a\u4ec0\u4e48\u4e0d\u80fd\u5728\u5b50\u67e5\u8be2\u7684 from \u5b50\u53e5\u4e2d\u66f4\u65b0\u5f53\u524d\u67e5\u8be2\u7684\u8868\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5728 MySQL \u4e2d\uff0c\u4e3a\u4ec0\u4e48\u4e0d\u80fd\u5728\u5b50\u67e5\u8be2\u7684 from \u5b50\u53e5\u4e2d\u66f4\u65b0\u5f53\u524d\u67e5\u8be2\u7684\u8868\uff1f<\/h1>\n<p>\u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u6253\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\u5427\uff01\u6587\u4e2d\u5185\u5bb9\u5305\u542b\u7b49\u7b49\u77e5\u8bc6\u70b9&#8230;\u5e0c\u671b\u4f60\u80fd\u5728\u9605\u8bfb\u672c\u6587\u540e\uff0c\u80fd\u771f\u771f\u5b9e\u5b9e\u5b66\u5230\u77e5\u8bc6\u6216\u8005\u5e2e\u4f60\u89e3\u51b3\u5fc3\u4e2d\u7684\u7591\u60d1\uff0c\u4e5f\u6b22\u8fce\u5927\u4f6c\u6216\u8005\u65b0\u4eba\u670b\u53cb\u4eec\u591a\u7559\u8a00\u8bc4\u8bba\uff0c\u591a\u7ed9\u5efa\u8bae\uff01\u8c22\u8c22\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241114\/17315771756735c55700bde.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>SQL \u67e5\u8be2\u8868\u5185\u4e0d\u91cd\u590d\u8bb0\u5f55\u7684\u795e\u79d8\u5305\u88f9<\/strong><\/p>\n<p>\u5728\u6267\u884c SQL \u67e5\u8be2\u8bed\u53e5\u65f6\uff0c\u4f60\u53ef\u80fd\u4f1a\u9047\u5230\u8fd9\u6837\u7684\u9519\u8bef\uff1a&#8221;SQL \u9519\u8bef [1093] [HY000]: You can&#8217;t specify target table &#8216;sys_post&#8217; for update in FROM clause&#8221;\u3002\u8fd9\u901a\u5e38\u662f\u56e0\u4e3a\u4f60\u8bd5\u56fe\u5728\u4e00\u4e2a\u5b50\u67e5\u8be2\u7684 from \u5b50\u53e5\u4e2d\u66f4\u65b0\u5f53\u524d\u6b63\u5728\u67e5\u8be2\u7684\u8868\u3002<\/p>\n<p>\u7136\u800c\uff0c\u5982\u679c\u5728\u5b50\u67e5\u8be2\u5468\u56f4\u6dfb\u52a0\u4e00\u5c42\u5305\u88f9\uff0c\u5373\u4f7f\u7528\u4e00\u4e2a\u6d3e\u751f\u8868\u5e76\u901a\u8fc7\u522b\u540d\u5f15\u7528\u8be5\u8868\uff0c\u67e5\u8be2\u5c31\u80fd\u6210\u529f\u6267\u884c\u3002<\/p>\n<p><strong>MySQL \u7684\u7279\u6b8a\u6027<\/strong><\/p>\n<p>\u8fd9\u79cd\u884c\u4e3a\u662f MySQL \u7279\u6709\u7684\u3002\u5176\u4ed6\u5927\u578b\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\uff0c\u5982 Oracle \u548c SQL Server\uff0c\u6ca1\u6709\u8fd9\u6837\u7684\u9650\u5236\u3002<\/p>\n<p><strong>\u5b98\u65b9\u89e3\u91ca<\/strong><\/p>\n<p>MySQL \u5b98\u65b9\u552f\u4e00\u5bf9\u8fd9\u4e00\u884c\u4e3a\u7684\u89e3\u91ca\u662f\uff1a&#8221;You cannot update a table and select directly from the same table in a subquery.&#8221;\uff08\u4f60\u4e0d\u80fd\u66f4\u65b0\u4e00\u4e2a\u8868\u5e76\u5728\u4e00\u4e2a\u5b50\u67e5\u8be2\u4e2d\u76f4\u63a5\u4ece\u540c\u4e00\u5f20\u8868\u4e2d\u9009\u62e9\u3002\uff09<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u5b98\u65b9\u63d0\u4f9b\u7684\u89e3\u51b3\u65b9\u6848\u662f\u4f7f\u7528\u591a\u8868\u66f4\u65b0\uff0c\u5176\u4e2d\u4e00\u4e2a\u8868\u6d3e\u751f\u81ea\u4f60\u5b9e\u9645\u4e0a\u5e0c\u671b\u66f4\u65b0\u7684\u8868\uff0c\u5e76\u4f7f\u7528\u522b\u540d\u5f15\u7528\u6d3e\u751f\u8868\u3002<\/p>\n<p><strong>\u539f\u56e0\u731c\u6d4b<\/strong><\/p>\n<p>\u81f3\u4e8e\u4e3a\u4ec0\u4e48 MySQL \u6709\u8fd9\u6837\u5947\u602a\u7684\u9650\u5236\uff0c\u539f\u56e0\u4e0d\u5f97\u800c\u77e5\u3002\u53ef\u80fd\u662f\u4e3a\u4e86\u9632\u6b62\u4e00\u4e9b\u610f\u5916\u7684\u66f4\u65b0\u6216\u51b2\u7a81\uff0c\u4f46\u5177\u4f53\u7684\u89e3\u91ca\u5b98\u65b9\u5e76\u6ca1\u6709\u7ed9\u51fa\u3002<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u5728 MySQL \u4e2d\uff0c\u4e3a\u4ec0\u4e48\u4e0d\u80fd\u5728\u5b50\u67e5\u8be2\u7684 from \u5b50\u53e5\u4e2d\u66f4\u65b0\u5f53\u524d\u67e5\u8be2\u7684\u8868\uff1f\u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 MySQL \u4e2d\uff0c\u4e3a\u4ec0\u4e48\u4e0d\u80fd\u5728&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-200783","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200783","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=200783"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200783\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200783"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200783"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200783"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}