那个更新查询不起作用?

时间:2017-11-24 13:44:06

标签: mysql sql-update rows-affected

你好男孩和女孩:)

我有这个问题:

SELECT * FROM customer
INNER JOIN address ON customer.customer_id = address.customer_id
WHERE address.country_id = 176

所以我想将custome.status更新为0 我尝试使用该查询,但“0行受影响”:

UPDATE customer
INNER JOIN address ON customer.customer_id = address.customer_id
SET customer.status = 0
WHERE address.country_id = 176

我有大约200个人,地址为address.country_id = 176!

任何想法,谢谢你!

1 个答案:

答案 0 :(得分:1)

您可以使用EXISTS而不是JOIN

尝试不同的方法
UPDATE
  customer
SET
  status = 0
WHERE
  EXISTS (
    SELECT *
    FROM address A
    WHERE customer.customer_id = A.customer_id AND country_id = 176
  )

无法回想起,但有可能MySQL不会报告状态已经等于0的记录的变化吗?