How can I do an UPDATE statement with JOIN in SQL Server?

前端 未结 16 1242
名媛妹妹
名媛妹妹 2020-11-21 11:51

I need to update this table in SQL Server with data from its \'parent\' table, see below:

Table: sale

id (int)
udid         


        
16条回答
  •  被撕碎了的回忆
    2020-11-21 12:15

    A standard SQL approach would be

    UPDATE ud
    SET assid = (SELECT assid FROM sale s WHERE ud.id=s.id)
    

    On SQL Server you can use a join

    UPDATE ud
    SET assid = s.assid
    FROM ud u
    JOIN sale s ON u.id=s.id
    

提交回复
热议问题