使用同一个表中另一行的数据更新行

我有一张桌子,看起来像这样

ID | NAME | VALUE | ---------------------------- 1 | Test | VALUE1 | 2 | Test2 | VALUE2 | 1 | Test2 | | 4 | Test | | 1 | Test3 | VALUE3 | 

我正在寻找一种方法来更新值'Test2'和'testing'与'VALUE'列中的其他行的数据具有相同的'名称'(这里的ID不是唯一的,ID的组合键和NAME使一行独一无二)。 例如,我正在寻找的输出是:

 ID | NAME | VALUE | ---------------------------- 1 | Test | VALUE1 | 2 | Test2 | VALUE2 | 1 | Test2 | VALUE2 | 4 | Test | VALUE1 | 1 | Test3 | VALUE3 | 

如果是在另一个表中,我会很好,但我不知道如何在当前表中引用具有相同NAME值的不同行。

更新

修改manji查询后,下面是我用于工作解决scheme的查询。 谢谢大家!

 UPDATE data_table dt1, data_table dt2 SET dt1.VALUE = dt2.VALUE WHERE dt1.NAME = dt2.NAME AND dt1.VALUE = '' AND dt2.VALUE != '' 

尝试这个:

 UPDATE data_table t, (SELECT DISTINCT ID, NAME, VALUE FROM data_table WHERE VALUE IS NOT NULL AND VALUE != '') t1 SET t.VALUE = t1.VALUE WHERE t.ID = t1.ID AND t.NAME = t1.NAME 

这是我的去

 UPDATE test as t1 INNER JOIN test as t2 ON t1.NAME = t2.NAME AND t2.value IS NOT NULL SET t1.VALUE = t2.VALUE; 

编辑:删除多余的t1.id != t2.id条件。

 Update MyTable Set Value = ( Select Min( T2.Value ) From MyTable As T2 Where T2.Id <> MyTable.Id And T2.Name = MyTable.Name ) Where ( Value Is Null Or Value = '' ) And Exists ( Select 1 From MyTable As T3 Where T3.Id <> MyTable.Id And T3.Name = MyTable.Name ) 
 UPDATE financialyear SET firstsemfrom = dt2.firstsemfrom, firstsemto = dt2.firstsemto, secondsemfrom = dt2.secondsemfrom, secondsemto = dt2.secondsemto from financialyear dt2 WHERE financialyear.financialyearkey = 141 AND dt2.financialyearkey = 140 

如果您只需要插入另一行中的数据的新行,

  insert into ORDER_ITEM select * from ORDER_ITEM where ITEM_NUMBER =123;