假设我有一个包含两列的简单表格,userid
并且email
.
如何更改值存在于多行email
中的所有值?email
例如,假设该email
值blah@blah.com
存在于 4 行中。我不想删除这 4 行,我只想将email
所有 4 行的列设置为''
.
什么查询会在 MySQL 中做到这一点?
此请求获取存在于 1 行以上的电子邮件:
SELECT email, COUNT(email) AS c
FROM table
GROUP BY email
HAVING c > 1
因此,您只需在更新查询中使用它:
UPDATE table SET email = ''
WHERE email IN (
SELECT email, COUNT(email) AS c
FROM table
GROUP BY email
HAVING c > 1
)
Update t
Set t.Email = ''
Where t.Email in (Select email from YourTable group by email having count(*)>1)