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

前端 未结 16 1287
名媛妹妹
名媛妹妹 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:06

    Simplified update query using JOIN-ing multiple tables.

       UPDATE
            first_table ft
            JOIN second_table st ON st.some_id = ft.some_id
            JOIN third_table tt  ON tt.some_id = st.some_id
            .....
        SET
            ft.some_column = some_value
        WHERE ft.some_column = 123456 AND st.some_column = 123456
    

    Note - first_table, second_table, third_table and some_column like 123456 are demo table names, column names and ids. Replace them with the valid names.

提交回复
热议问题