Update row with data from another row in the same table

前端 未结 5 1406
一向
一向 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:17

    Here's my go:

    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;
    

    EDIT: Removed superfluous t1.id != t2.id condition.

提交回复
热议问题