• <legend id='iI0Ex'><style id='iI0Ex'><dir id='iI0Ex'><q id='iI0Ex'></q></dir></style></legend>
  • <small id='iI0Ex'></small><noframes id='iI0Ex'>

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

      <tfoot id='iI0Ex'></tfoot>
      • <bdo id='iI0Ex'></bdo><ul id='iI0Ex'></ul>
      1. mysql - 如何在MySQL中使用自动增量字段复制一行并插入同一个表中?

        时间:2023-06-01
          <tbody id='cReFq'></tbody>

        1. <small id='cReFq'></small><noframes id='cReFq'>

            <bdo id='cReFq'></bdo><ul id='cReFq'></ul>

              <tfoot id='cReFq'></tfoot>
                <i id='cReFq'><tr id='cReFq'><dt id='cReFq'><q id='cReFq'><span id='cReFq'><b id='cReFq'><form id='cReFq'><ins id='cReFq'></ins><ul id='cReFq'></ul><sub id='cReFq'></sub></form><legend id='cReFq'></legend><bdo id='cReFq'><pre id='cReFq'><center id='cReFq'></center></pre></bdo></b><th id='cReFq'></th></span></q></dt></tr></i><div id='cReFq'><tfoot id='cReFq'></tfoot><dl id='cReFq'><fieldset id='cReFq'></fieldset></dl></div>
                <legend id='cReFq'><style id='cReFq'><dir id='cReFq'><q id='cReFq'></q></dir></style></legend>
                  本文介绍了mysql - 如何在MySQL中使用自动增量字段复制一行并插入同一个表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 MySQL 中,我尝试使用 autoincrement column ID=1 复制一行,然后将数据插入到同一个表中作为新表列 ID=2 的行.

                  In MySQL I am trying to copy a row with an autoincrement column ID=1 and insert the data into same table as a new row with column ID=2.

                  如何在单个查询中执行此操作?

                  How can I do this in a single query?

                  推荐答案

                  使用 INSERT ... SELECT:

                  insert into your_table (c1, c2, ...)
                  select c1, c2, ...
                  from your_table
                  where id = 1
                  

                  其中 c1, c2, ... 是除 id 之外的所有列.如果您想显式插入 id 为 2,则将其包含在您的 INSERT 列列表和您的 SELECT 中:

                  where c1, c2, ... are all the columns except id. If you want to explicitly insert with an id of 2 then include that in your INSERT column list and your SELECT:

                  insert into your_table (id, c1, c2, ...)
                  select 2, c1, c2, ...
                  from your_table
                  where id = 1
                  

                  当然,在第二种情况下,您必须处理可能重复的 id 2.

                  You'll have to take care of a possible duplicate id of 2 in the second case of course.

                  这篇关于mysql - 如何在MySQL中使用自动增量字段复制一行并插入同一个表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何仅在内存中运行 Django 的测试数据库? 下一篇:你如何调试 MySQL 存储过程?

                  相关文章

                  • <bdo id='9OaZi'></bdo><ul id='9OaZi'></ul>
                  <legend id='9OaZi'><style id='9OaZi'><dir id='9OaZi'><q id='9OaZi'></q></dir></style></legend>

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

                    <small id='9OaZi'></small><noframes id='9OaZi'>

                    1. <tfoot id='9OaZi'></tfoot>