MySQL:从 IN 中删除
我知道这是一个简单的语法问题。尝试从子查询中删除所有用户:
delete from users
where id IN (
select u.id
from users u
where not exists (select * from stickies i where i.user_id = u.id)
group by u.email
having count(*) > 1
)
收到此错误:
error : You can't specify target table 'users' for update in FROM clause
子查询工作正常(返回用户 ID 列表)。
I know this is a simple syntax issue. Trying to delete all users from a subquery:
delete from users
where id IN (
select u.id
from users u
where not exists (select * from stickies i where i.user_id = u.id)
group by u.email
having count(*) > 1
)
Getting this error:
error : You can't specify target table 'users' for update in FROM clause
The subquery works fine (returns list of user id's).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
注意:在内部查询中,您按电子邮件分组,但选择用户 ID。这可能会返回不确定的结果。
Note: in the inner query, you are grouping by email, but selecting a user ID. this may return non deterministic results.