错误 1093 指出如果您的子查询查询要从中删除的表,则您无法使用子查询进行更新或删除。
所以你不能这样做
delete from table1 where id in (select something from table1 where condition) ;
好的,解决该限制的最佳方法是什么(假设您确实需要子查询来执行删除并且不能完全消除自引用子查询?)
编辑:
下面是有兴趣的人的问题:
mysql> desc adjacencies ; +---------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+---------+------+-----+---------+-------+ | parent | int(11) | NO | PRI | NULL | | | child | int(11) | NO | PRI | NULL | | | pathLen | int(11) | NO | | NULL | | +---------+---------+------+-----+---------+-------+ -- The query is going to -- tell all my children to -- stop thinking my old parents -- are still their parents delete from adjacencies where parent in ( -- ALL MY PARENTS,grandparents select parent from adjacencies where child=@me and parent!=@me ) -- only concerns the relations of my -- grandparents WHERE MY CHILDREN ARE CONCERNED and child in ( -- get all my children select child from adjacencies where parent=@me ) ;
So what I've tried so far is creating a temporary table called adjsToDelete
create temporary table adjsToRemove( parent int, child int ) ;
insert into adjsToRemove...
现在我有一组要删除的关系,其中每个父/子对唯一标识要删除的行。但是现在如何从邻接表中删除每个对?
看来我需要为 adjacencies
中的每个条目添加一个唯一的 auto_increment
ed 键,对吗?
最佳答案
解决方法,在 http://bugs.mysql.com/bug.php?id=6980 中找到,对我有用的是为将返回项目的子查询创建一个别名。所以
delete from table1 where id in
(select something from table1 where condition)
将更改为
delete from table1 where id in
(select p.id from (select something from table1 where condition) as p)
关于MySQL 解决错误 1093,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4484779/