{"id":1032,"date":"2020-09-07T17:07:08","date_gmt":"2020-09-07T09:07:08","guid":{"rendered":"http:\/\/www.gbase8.cn\/?p=1032"},"modified":"2020-09-08T06:59:49","modified_gmt":"2020-09-07T22:59:49","slug":"gbase-8a%e6%89%a7%e8%a1%8cupdate-sql%e6%8a%a5%e9%94%99%e6%97%a0%e6%b3%95%e6%9b%b4%e6%96%b0%e5%a4%9a%e8%a1%8c%e6%95%b0%e6%8d%ae-can-not-update-one-row-to-multi-data","status":"publish","type":"post","link":"https:\/\/www.gbase8.cn\/en\/1032","title":{"rendered":"\u5357\u5927\u901a\u7528GBase 8a\u6267\u884cupdate SQL\u62a5\u9519\u65e0\u6cd5\u66f4\u65b0\u591a\u884c\u6570\u636e can not update one row to multi-data"},"content":{"rendered":"<p>GBase 8a\u5728update\u65f6\uff0c\u5bf9\u4e8e\u7cbe\u786e\u7684\u6761\u4ef6\uff0c\u53ea\u80fd\u6709\u4e00\u4e2a\u7cbe\u786e\u5730\u503c\u3002 \u5982\u679c\u5b58\u5728\u591a\u4e2a\uff0c\u5219\u4f1a\u62a5 can not update one row to multi-data \u9519\u8bef\uff0c\u5982\u679c\u662f\u5728\u5b50\u67e5\u8be2\u4e2d\uff0c\u4f1a\u62a5 Subquery return more than 1 row\u9519\u8bef\u3002<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Directory Navigation<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2aef40a9694\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewbox=\"0 0 24 24\" version=\"1.2\" baseprofile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2aef40a9694\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.gbase8.cn\/en\/1032\/#%E6%8A%A5%E9%94%99%E6%A0%B7%E4%BE%8B\" >\u62a5\u9519\u6837\u4f8b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.gbase8.cn\/en\/1032\/#%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88\" >Solution<\/a><\/li><\/ul><\/nav><\/div>\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%8A%A5%E9%94%99%E6%A0%B7%E4%BE%8B\"><\/span>\u62a5\u9519\u6837\u4f8b<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> create table t1(id int, value int);\nQuery OK, 0 rows affected (Elapsed: 00:00:00.18)\n\ngbase> insert into t1 values(1,'0');\nQuery OK, 1 row affected (Elapsed: 00:00:00.07)\n\ngbase> create table t2(id int, value int);\nQuery OK, 0 rows affected (Elapsed: 00:00:00.10)\n\ngbase> insert into t2 values(1,123);\nQuery OK, 1 row affected (Elapsed: 00:00:00.07)\n\ngbase> insert into t2 values(1,234);\nQuery OK, 1 row affected (Elapsed: 00:00:00.07)\n\ngbase> select * from t1;\n+------+-------+\n| id   | value |\n+------+-------+\n|    1 |     0 |\n+------+-------+\n1 row in set (Elapsed: 00:00:00.00)\n\ngbase> select * from t2;\n+------+-------+\n| id   | value |\n+------+-------+\n|    1 |   123 |\n|    1 |   234 |\n+------+-------+\n2 rows in set (Elapsed: 00:00:00.01)\n\ngbase> update t1 set value=(select value from t2 where t2.id=t1.id);\nERROR 1709 (HY000): &#91;10.0.2.107:5050](GBA-02AD-0005)Failed to query in gnode:\nDETAIL: (GBA-01EX-0002) Subquery return more than 1 row\nSQL: \/*::ffff:10.0.2.107_118_18_2020-09-03_20:47:02*\/ UPDATE `testdb`.`t1_n1` `testdb.t1` SET `testdb.t1`.`value` = ( SELECT `testdb.t2`.`value` as `value` From  `gctmpdb`.`_tmp_1795293194_118_t51_1_1599096136_s` `testdb.t2` WHERE (`testdb.t2`.`id` = `testdb.t1`.`id`));\ngbase> update t1,t2 set t1.value=t2.value where t1.id=t2.id;\nERROR 1709 (HY000): &#91;10.0.2.107:5050](GBA-02AD-0005)Failed to query in gnode:\nDETAIL: (GBA-01EX-700) Gbase general error: can not update one row to multi-data\nSQL: \/*::ffff:10.0.2.107_118_19_2020-09-03_20:47:28*\/ UPDATE `gctmpdb`._tmp_1795293194_118_t52_1_1599096136_s INNER JOIN `testdb`.`t1_n1` `testdb.t1` ON (`testdb.t1`.`id` = `_tmp_1795293194_118_t52_1_1599096136_s`.`id`) SET `testdb.t1`.`value` = `_tmp_1795293194_118_t52_1_1599096136_s`.`testdb.t1.value`;\ngbase>\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88\"><\/span>Solution<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u9996\u5148\u4ece\u4e1a\u52a1\u4e0a\u8981\u907f\u514d\u8fd9\u79cd1\uff1an\u66f4\u65b0\u7684\u60c5\u51b5\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u5b9e\u5728\u907f\u514d\u4e0d\u4e86\uff0c\u5bf9\u4e8e\u5b50\u67e5\u8be2\uff0c\u53ef\u4ee5\u7528limit\u9650\u5b9a\u7ed3\u679c\u96c6\u3002\u6bd4\u5982<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> update t1 set value=(select value from t2 where t2.id=t1.id limit 1);\nQuery OK, 1 row affected (Elapsed: 00:00:00.28)\nRows matched: 1  Changed: 1  Warnings: 0\n\ngbase> select * from t1;\n+------+-------+\n| id   | value |\n+------+-------+\n|    1 |   234 |\n+------+-------+\n1 row in set (Elapsed: 00:00:00.00)\n<\/code><\/pre>\n\n\n\n<p>\u5bf9\u4e8e\u591a\u8868\u5173\u8054\u66f4\u65b0\uff0c\u65e0\u89e3\u3002\u8bf7\u8c03\u6574\u4e1a\u52a1\u6216\u6539\u5199SQL\u3002<\/p>","protected":false},"excerpt":{"rendered":"<p>\u5357\u5927\u901a\u7528GBase 8a\u5728update\u65f6\uff0c\u5bf9\u4e8e\u7cbe\u786e\u7684\u6761\u4ef6\uff0c\u53ea\u80fd\u6709\u4e00\u4e2a\u7cbe\u786e\u5730\u503c\u3002 \u5982\u679c\u5b58\u5728\u591a\u4e2a\uff0c\u5219\u4f1a\u62a5 can not update one row to multi-data \u9519\u8bef\uff0c\u5982\u679c\u662f\u5728\u5b50\u67e5\u8be2\u4e2d\uff0c\u4f1a\u62a5 Subquery return more than 1 row\u9519\u8bef\u3002<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[54],"tags":[],"class_list":["post-1032","post","type-post","status-publish","format-standard","hentry","category-gbase8a"],"_links":{"self":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/1032","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/comments?post=1032"}],"version-history":[{"count":1,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/1032\/revisions"}],"predecessor-version":[{"id":1033,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/1032\/revisions\/1033"}],"wp:attachment":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/media?parent=1032"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/categories?post=1032"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/tags?post=1032"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}