SQL Server - inner join when updating

Sql ServerInner Join

Sql Server Problem Overview


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'

Sql Server Solutions


Solution 1 - Sql Server

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';

Solution 2 - Sql Server

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'

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLeeTeeView Question on Stackoverflow
Solution 1 - Sql ServerAaron BertrandView Answer on Stackoverflow
Solution 2 - Sql ServerBridgeView Answer on Stackoverflow