SQL update query using joins

后端 未结 11 1818
天涯浪人
天涯浪人 2020-11-22 01:15

I have to update a field with a value which is returned by a join of 3 tables.

Example:

select
    im.itemid
    ,im.sku as iSku
    ,gm.SKU as GSKU         


        
11条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 01:56

    Let me just add a warning to all the existing answers:

    When using the SELECT ... FROM syntax, you should keep in mind that it is proprietary syntax for T-SQL and is non-deterministic. The worst part is, that you get no warning or error, it just executes smoothly.

    Full explanation with example is in the documentation:

    Use caution when specifying the FROM clause to provide the criteria for the update operation. The results of an UPDATE statement are undefined if the statement includes a FROM clause that is not specified in such a way that only one value is available for each column occurrence that is updated, that is if the UPDATE statement is not deterministic.

提交回复
热议问题