admin

使用连接的 SQL 更新查询

sql

我必须用一个由 3 个表的连接返回的值来更新一个字段。

例子:

select
    im.itemid
    ,im.sku as iSku
    ,gm.SKU as GSKU
    ,mm.ManufacturerId as ManuId
    ,mm.ManufacturerName
    ,im.mf_item_number
    ,mm.ManufacturerID
from 
    item_master im, group_master gm, Manufacturer_Master mm 
where
    im.mf_item_number like 'STA%'
    and im.sku=gm.sku
    and gm.ManufacturerID = mm.ManufacturerID
    and gm.manufacturerID=34

我想用在上述条件中加入的其他一些值更新mf_item_number表的字段值item_master

如何在 MS SQL Server 中执行此操作?


阅读 156

收藏
2021-07-01

共1个答案

admin

UPDATE im
SET mf_item_number = gm.SKU –etc
FROM item_master im
JOIN group_master gm
ON im.sku = gm.sku
JOIN Manufacturer_Master mm
ON gm.ManufacturerID = mm.ManufacturerID
WHERE im.mf_item_number like ‘STA%’ AND
gm.manufacturerID = 34

2021-07-01