本文翻譯自:SQL Server - inner join when updating [duplicate]
This question already has an answer here: 這個問題在這裏已有答案:
- Update a table using JOIN in SQL Server? 在SQL Server中使用JOIN更新表? 10 answers 10個答案
I have the below query which does not work. 我有以下查詢不起作用。 What am I doing wrong? 我究竟做錯了什麼? Is this even possible? 這甚至可能嗎?
UPDATE ProductReviews AS R
INNER JOIN products AS P
ON R.pid = P.id
SET R.status = '0'
WHERE R.id = '17190'
AND P.shopkeeper = '89137'
#1樓
參考:https://stackoom.com/question/eENz/SQL-Server-更新-重複-時的內部聯接
#2樓
This should do it: 這應該這樣做:
UPDATE ProductReviews
SET ProductReviews.status = '0'
FROM ProductReviews
INNER JOIN products
ON ProductReviews.pid = products.id
WHERE ProductReviews.id = '17190'
AND products.shopkeeper = '89137'
#3樓
UPDATE R
SET R.status = '0'
FROM dbo.ProductReviews AS R
INNER JOIN dbo.products AS P
ON R.pid = P.id
WHERE R.id = '17190'
AND P.shopkeeper = '89137';