MySQL Getting around error 1093

后端 未结 5 1025
伪装坚强ぢ
伪装坚强ぢ 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 03:43

    A workaround, found in http://bugs.mysql.com/bug.php?id=6980, that worked for me is to create an alias to the sub query that will return the items. So

    delete from table1 where id in 
      (select something from table1 where condition)
    

    would be changed to

    delete from table1 where id in
      (select p.id from (select something from table1 where condition) as p)
    

提交回复
热议问题