Error 1093 states that you cannot UPDATE or DELETE using a subquery if your subquery requests a table that you delete.
So you can not do
delete from table1 where id in (select something from table1 where condition) ;
Well, whatโs the best way to get around this limitation (if you really need to execute the subquery in order to perform the deletion and cannot completely exclude the independent reference subquery?)
Edit:
Here's a request for those interested:
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, so far I have been trying to create a temporary table called adjsToDelete
create temporary table adjsToRemove( parent int, child int ) ; insert into adjsToRemove...
So now I have a set of delete relationships, where the parent / child pairs uniquely identify the row to delete. But how can I remove every pair from the adjacency table?
It seems I need to add a unique auto_increment ed key for each entry at adjacencies , right?
source share