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
,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
I want to update the mf_item_number
field values of table item_master
with some other value which is joined in the above condition.
How can I do this in MS SQL Server?
Adapting this to MySQL -- there is no
FROM
clause inUPDATE
, but this works:You can use the following query:
You can specify additional tables used in determining how and what to update with the "FROM " clause in the UPDATE statement, like this:
In the WHERE clause, you need to provide the conditions and join operations to bind these tables together.
Marc
You can update with
MERGE
Command with much more control overMATCHED
andNOT MATCHED
:(I slightly changed the source code to demonstrate my point)Try like this...