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

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

        <legend id='mE0LD'><style id='mE0LD'><dir id='mE0LD'><q id='mE0LD'></q></dir></style></legend>
        <tfoot id='mE0LD'></tfoot>
          <bdo id='mE0LD'></bdo><ul id='mE0LD'></ul>
      2. Mysql 用同一表中的另一行值更新一行

        时间:2023-07-29

          <legend id='0V3pI'><style id='0V3pI'><dir id='0V3pI'><q id='0V3pI'></q></dir></style></legend>

          <small id='0V3pI'></small><noframes id='0V3pI'>

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

                <tbody id='0V3pI'></tbody>
              • <tfoot id='0V3pI'></tfoot>

                1. 本文介绍了Mysql 用同一表中的另一行值更新一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一张桌子.我想用同一个表中的第 10 行值更新第 5 行.例如:

                  I have a table. I want to update the 5th row with 10th row values from the same table. For example:

                  SlNo   Name Quali   Exp
                  1        x   B.E     2
                  2        y   BSC     3
                  3        Z   B.A     1.5
                  4        A   MSC     2
                  5        B   MBA     5
                  

                  这里我想用第 5 行的值更新第二行.

                  Here i want to update second row with the value of 5th row.

                  这是我当前的查询:

                      UPDATE table 
                        SET Name=(select Name from table where slNo='5'),
                                 Quali=(select Quali from  table where slNo='5'),
                                 Exp=(select Exp from table where slNo='5') 
                        where slNo='3';
                  

                  这工作正常......但是如果有超过 20 列,以这种方式编写查询会变得很费力,因为对于每一列,我必须包含另一个子查询......还有其他方法可以编写吗?查询以使用同一表中另一行的所有值更新整行?

                  this is working fine ... but if there are more than 20 columns it becomes laborious to write a query this way, because for each column I have to include another sub-query... is there any other way to write query to update the whole row with all values from the other row in the same table?

                  推荐答案

                  使用多表的自联接 UPDATE 语法:

                  Use a self-join with the multiple table UPDATE syntax:

                  UPDATE `table` AS t1 JOIN `table` AS t2 ON t2.slNo = 5
                  SET    t1.Name = t2.Name, t1.Quali = t2.Quali, t1.Exp = t2.Exp
                  WHERE  t1.slNo = 3
                  

                  这篇关于Mysql 用同一表中的另一行值更新一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:来自 mysqli_Query 的回显结果 下一篇:分页的最低限度?

                  相关文章

                  最新文章

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

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

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