MySQL Getting around error 1093

后端 未结 5 1045
伪装坚强ぢ
伪装坚强ぢ 2020-12-07 03:21

Error 1093 states that you can\'t UPDATE or DELETE using a subquery if your subquery queries the table you are deleting from.

So you can\'t do

delete         


        
5条回答
  •  忘掉有多难
    2020-12-07 04:01

    You can do

    delete t1,t2 
    FROM  table1 t1  
    INNER JOIN 
    table1 t2 ON (t2.something = t1.id);
    

    For the query in the question, this should be equivalent:

    delete A
    from adjacencies A
    join adjacencies B ON A.parent = B.parent AND B.child=@me AND B.parent != @me
    join adjacencies C ON A.child = C.child AND C.parent=@me
    

提交回复
热议问题