更新多个值在Mysql中查询

时间:2017-08-22 06:40:25

标签: mysql

 SELECT id,login,contact_number, store_id, COUNT(contact_number) AS COUNT
   FROM USER 
  WHERE store_id = 1 
    AND is_number_verified = 1
  GROUP BY contact_number 
 HAVING COUNT(contact_number) > 1 

现在我想将number_verified的所有值更新为0并希望保留      为每个用户验证了1行。我试过这个但是没有工作

UPDATE `user` SET is_number_verified = 0
 WHERE id IN
(  
 SELECT id 
   FROM USER where store_id = 1 
    AND is_number_verified = 1
  GROUP BY contact_number 
 HAVING COUNT(contact_number) > 1 
) 

1 个答案:

答案 0 :(得分:0)

您可以尝试使用另一个内部查询,例如:

UPDATE `user` SET is_number_verified = 0
WHERE id IN
(SELECT temp.id FROM (      
SELECT id,login,contact_number, store_id, COUNT(contact_number) AS COUNT
FROM USER 
WHERE store_id = 1 AND is_number_verified = 1
GROUP BY contact_number 
HAVING COUNT(contact_number) > 1) AS temp)