Update row with data from another row in the same table

前端 未结 5 1399
一向
一向 2020-11-27 02:59

I\'ve got a table which looks something like this

ID   |   NAME    |  VALUE  |
----------------------------
 1   |   Test    |  VALUE1 |
 2   |   Test2   |          


        
5条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 03:32

    Try this:

    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
    

提交回复
热议问题