MySQL Error 1093 - Can't specify target table for update in FROM clause
Asked 07 September, 2021
Viewed 2.1K times
  • 60
Votes

I have a table story_category in my database with corrupt entries. The next query returns the corrupt entries:

SELECT * 
FROM  story_category 
WHERE category_id NOT IN (
    SELECT DISTINCT category.id 
    FROM category INNER JOIN 
       story_category ON category_id=category.id);

I tried to delete them executing:

DELETE FROM story_category 
WHERE category_id NOT IN (
    SELECT DISTINCT category.id 
    FROM category 
      INNER JOIN story_category ON category_id=category.id);

But I get the next error:


  

#1093 - You can't specify target table 'story_category' for update in FROM clause

How can I overcome this?

16 Answer