SQL Server - 更新[重复]时的内部联接

本文翻译自: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';

你可能感兴趣的:(sql-server,inner-join)