<bdo id='2peQo'></bdo><ul id='2peQo'></ul>

    1. <tfoot id='2peQo'></tfoot>
      <i id='2peQo'><tr id='2peQo'><dt id='2peQo'><q id='2peQo'><span id='2peQo'><b id='2peQo'><form id='2peQo'><ins id='2peQo'></ins><ul id='2peQo'></ul><sub id='2peQo'></sub></form><legend id='2peQo'></legend><bdo id='2peQo'><pre id='2peQo'><center id='2peQo'></center></pre></bdo></b><th id='2peQo'></th></span></q></dt></tr></i><div id='2peQo'><tfoot id='2peQo'></tfoot><dl id='2peQo'><fieldset id='2peQo'></fieldset></dl></div>

    2. <small id='2peQo'></small><noframes id='2peQo'>

    3. <legend id='2peQo'><style id='2peQo'><dir id='2peQo'><q id='2peQo'></q></dir></style></legend>

      带有 WHERE SELECT 子查询错误的 MYSQL 更新

      MYSQL update with WHERE SELECT subquery error(带有 WHERE SELECT 子查询错误的 MYSQL 更新)

      <legend id='CZDyi'><style id='CZDyi'><dir id='CZDyi'><q id='CZDyi'></q></dir></style></legend>
            <bdo id='CZDyi'></bdo><ul id='CZDyi'></ul>

            <small id='CZDyi'></small><noframes id='CZDyi'>

              <tfoot id='CZDyi'></tfoot>
            1. <i id='CZDyi'><tr id='CZDyi'><dt id='CZDyi'><q id='CZDyi'><span id='CZDyi'><b id='CZDyi'><form id='CZDyi'><ins id='CZDyi'></ins><ul id='CZDyi'></ul><sub id='CZDyi'></sub></form><legend id='CZDyi'></legend><bdo id='CZDyi'><pre id='CZDyi'><center id='CZDyi'></center></pre></bdo></b><th id='CZDyi'></th></span></q></dt></tr></i><div id='CZDyi'><tfoot id='CZDyi'></tfoot><dl id='CZDyi'><fieldset id='CZDyi'></fieldset></dl></div>
                <tbody id='CZDyi'></tbody>

              1. 本文介绍了带有 WHERE SELECT 子查询错误的 MYSQL 更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在获取选择子查询以处理 UPDATE 时遇到问题.我正在尝试类似以下内容:

                I have an issue with getting select sub-queries to work on an UPDATE. I'm trying something like the following:

                UPDATE foo
                   SET bar=bar-1
                 WHERE baz=
                      (
                       SELECT baz
                       FROM foo
                       WHERE fooID='1'
                      )
                

                其中foo 是主键为fooID 的表名.barbaz 是 INT 类型.执行此操作时出现以下错误:

                Where foo is the table name with primary key fooID. bar and baz are of type INT. When executing this I get the following error:

                Error: A query failed. You can't specify target table 'foo' for update 
                in FROM clause
                

                推荐答案

                从此 网络文章

                此错误的原因是当您还在内部选择中使用同一表作为更新条件时,MySQL 不允许对表进行更新.文章接着提供了一个解决方案,那就是使用临时表.

                The reason for this error is that MySQL doesn’t allow updates to a table when you are also using that same table in an inner select as your update criteria. The article goes on to provide a solution, which is to use a temporary table.

                使用这个例子,你的更新应该是这样的:

                Using this example, your update should be this:

                update foo
                set bar = bar - 1
                where baz in
                (
                  select baz from
                  (
                    select baz
                    from foo
                    where fooID = '1'
                  ) as arbitraryTableName
                )
                

                这篇关于带有 WHERE SELECT 子查询错误的 MYSQL 更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)
                MySQL GROUP BY DateTime +/- 3 seconds(MySQL GROUP BY DateTime +/- 3 秒)

                      • <bdo id='akwu0'></bdo><ul id='akwu0'></ul>

                        <tfoot id='akwu0'></tfoot>
                          <tbody id='akwu0'></tbody>
                        <legend id='akwu0'><style id='akwu0'><dir id='akwu0'><q id='akwu0'></q></dir></style></legend>

                          <small id='akwu0'></small><noframes id='akwu0'>

                        1. <i id='akwu0'><tr id='akwu0'><dt id='akwu0'><q id='akwu0'><span id='akwu0'><b id='akwu0'><form id='akwu0'><ins id='akwu0'></ins><ul id='akwu0'></ul><sub id='akwu0'></sub></form><legend id='akwu0'></legend><bdo id='akwu0'><pre id='akwu0'><center id='akwu0'></center></pre></bdo></b><th id='akwu0'></th></span></q></dt></tr></i><div id='akwu0'><tfoot id='akwu0'></tfoot><dl id='akwu0'><fieldset id='akwu0'></fieldset></dl></div>