SQL Server - 更新[重複]時的內部聯接

本文翻譯自:SQL Server - inner join when updating [duplicate]

This question already has an answer here: 這個問題在這裏已有答案:

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';
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章