我有两张桌子:
Master Table Assets Table
-AssetNo- -AssetNo-
AssetNo
是PK,它是链接两个表的外键。现在,我想使用以下内容进行更新:
UPDATE Assets
SET status = 1
FROM Assets, Master
WHERE Assets.AssetNo = Master.AssetNo
如果我使用此命令,则具有相同assetno
的所有资产将自动更新为1。
如何使用特定的assetNo
IE进行编码:WHERE 111(from Assets)=111(from Master)
答案 0 :(得分:4)
如果我理解你的问题,我认为你的WHERE子句中只需要另一个条件:
UPDATE Assets
SET status = 1
FROM Assets, Master
WHERE Assets.AssetNo = Master.AssetNo
AND Assets.AssetNo = 111
答案 1 :(得分:1)
你使用的是什么sql引擎?像这样的东西适用于sql server:
Update a
SET Status = 1
FROM Assets a
JOIN Master m on a.AssetNo = m.AssetNo
WHERE a.AssetNo = 111
答案 2 :(得分:1)
UPDATE Assets SET status = 1
FROM Assets a JOIN Master m ON a.AssetNo = m.AssetNo
WHERE a.AssetNo = 999
答案 3 :(得分:1)
UPDATE a
SET a.Status = 1
FROM Assets AS a
INNER JOIN Master AS m ON a.AssetNo = m.AssetNo
WHERE m.AssetNo = @value