Update row with select on same table

后端 未结 5 511
醉话见心
醉话见心 2021-01-11 12:13

I\'m trying to update row with same table query. Context:

ID        |  LANG       |  TEXT
----------------------------------
1         |  EN         |  Hello         


        
5条回答
  •  天涯浪人
    2021-01-11 12:35

    For MS SQL you can use a join to do this, it might not work with other databases though:

    UPDATE t1
    SET t1.text = t2.text
    FROM table1 t1
    INNER JOIN table1 t2 ON t1.id = t2.id 
    WHERE t1.TEXT IS NULL AND t2.LANG = 'EN'
    

    Sample SQL Fiddle

提交回复
热议问题