更新具有重复条目的行
我的情况与其他相同问题,但我不想选择这些行,我想更新这些行。
我使用了 解决方案Scott Saunders 做了:
select * from table where email in (
select email from table group by email having count(*) > 1
)
这有效,但我想更改/更新这些条目中的行值,所以我尝试了:
UPDATE `members` SET `banned` = "1" WHERE `ip` IN (
SELECT `ip` FROM `members` GROUP BY `ip` HAVING COUNT(*) > 1
)
但我收到此错误:
您无法指定目标表 FROM 中的“成员”更新 条款
I have the same situation as this other question, but I don't want to select the rows, I want to update these rows.
I used the solution Scott Saunders made:
select * from table where email in (
select email from table group by email having count(*) > 1
)
That worked, but I wanted to change/update a row-value in these entries, so I tried:
UPDATE `members` SET `banned` = "1" WHERE `ip` IN (
SELECT `ip` FROM `members` GROUP BY `ip` HAVING COUNT(*) > 1
)
but I get this error:
You can't specify target table
'members' for update in FROM
clause
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用中间子查询来解决 1093 错误:
否则,在派生表上使用 JOIN:
Use an intermediate subquery to get around the 1093 error:
Otherwise, use a JOIN on a derived table:
此错误意味着您无法根据
members
表的条件更新members
表。在您的情况下,您尝试根据members
表的子查询更新members
表。在此过程中,您正在更改该表。把它想象成先有鸡再有蛋的悖论。您需要创建一个临时参考表或保存/粘贴 IP 范围才能运行该更新语句。
This error means you can't update the
members
table based on criteria of themembers
table. In your case, you are attempting to update themembers
table based on a subquery of themembers
table. In the process you are changing that table. Think of it like a chicken before the egg paradox.You'll need to make a temporary reference table or save/paste the ip ranges in order to run that update statement.