4

这是一个简单的查询,用于product使用来自helper.

UPDATE product p 
INNER JOIN helper h ON p.productcode = h.productcode
SET p.picture = h.picture;

但是如果我WHERE p.gotpicture=0在最后添加只更新 p.gotpicture=0 的记录而不是整个表,那么查询会更新 0 行。为什么?

4

2 回答 2

0

你的问题很容易解决,只要按照这个..

 UPDATE product p,helper h

   SET p.picture = h.picture

     where p.productcode = h.productcode

       and p.gotpicture=0;

试试上面的代码,你一定能克服你的问题。

于 2013-11-27T11:05:02.973 回答
0

我是测试仪,对我来说效果很好。

但是你可以测试这些:

UPDATE product p , helper h
SET p.picture = h.picture
WHERE p.gotpicture=0 
AND p.productcode = h.productcode;

或者

UPDATE product p 
SET p.picture = (select h.picture from helper h where p.productcode = h.productcode)
WHERE p.gotpicture=0 
AND p.productcode in (select  h.productcode from helper h);
于 2013-06-14T07:26:27.397 回答