SQL update query using joins

后端 未结 11 1824
天涯浪人
天涯浪人 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:46

    Did not use your sql above but here is an example of updating a table based on a join statement.

    UPDATE p
    SET    p.category = c.category
    FROM   products p
           INNER JOIN prodductcatagories pg
                ON  p.productid = pg.productid
           INNER JOIN categories c
                ON  pg.categoryid = c.cateogryid
    WHERE  c.categories LIKE 'whole%'
    

提交回复
热议问题