[Err] 1093 - You can't specify target table 's' for update in FROM clause


[Err] 1093 - You can't specify target table 's' for update in FROM clause
 
 
SQLの実行
DELETE from  book WHERE id IN(
SELECT id FROM (

SELECT id,name FROM book WHERE name  IN(
SELECT  name FROM book  GROUP BY name HAVING count(name) > 1
) 

) t WHERE id NOT IN (
SELECT  id FROM book  GROUP BY name HAVING count(name) > 1
 )

);

 
エラー:
[Err] 1093 - You can't specify target table 's' for update in FROM clause

 
SQL文の実行中にこのエラーが発生しました.なぜなら、このテーブルとデータを更新するときにクエリーが行われ、クエリーのデータが更新される条件が満たされているからです.
 
解決方法:削除するデータを第三者テーブルとしてクエリーし、削除します.
DELETE book from book , 
(
   SELECT id FROM (
		SELECT id FROM book WHERE name IN(SELECT  name FROM book  GROUP BY name HAVING count(name) > 1) 
   ) t 
   WHERE id NOT IN (SELECT  id FROM book  GROUP BY name HAVING count(name) > 1)
) as a 
WHERE book.id = a.id;