Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 32757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:48:48+00:00 2026-05-10T13:48:48+00:00

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

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T13:48:49+00:00Added an answer on May 10, 2026 at 1:48 pm

    Update: This answer covers the general error classification. For a more specific answer about how to best handle the OP’s exact query, please see other answers to this question

    In MySQL, you can’t modify the same table which you use in the SELECT part.
    This behaviour is documented at: http://dev.mysql.com/doc/refman/5.6/en/update.html

    Maybe you can just join the table to itself

    If the logic is simple enough to re-shape the query, lose the subquery and join the table to itself, employing appropriate selection criteria. This will cause MySQL to see the table as two different things, allowing destructive changes to go ahead.

    UPDATE tbl AS a INNER JOIN tbl AS b ON .... SET a.col = b.col 

    Alternatively, try nesting the subquery deeper into a from clause …

    If you absolutely need the subquery, there’s a workaround, but it’s ugly for several reasons, including performance:

    UPDATE tbl SET col = (   SELECT ... FROM (SELECT.... FROM) AS x); 

    The nested subquery in the FROM clause creates an implicit temporary table, so it doesn’t count as the same table you’re updating.

    … but watch out for the query optimiser

    However, beware that from MySQL 5.7.6 and onward, the optimiser may optimise out the subquery, and still give you the error. Luckily, the optimizer_switch variable can be used to switch off this behaviour; although I couldn’t recommend doing this as anything more than a short term fix, or for small one-off tasks.

    SET optimizer_switch = 'derived_merge=off'; 

    Thanks to Peter V. Mørch for this advice in the comments.

    Example technique was from Baron Schwartz, originally published at Nabble, paraphrased and extended here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to store messages data in a database & make a hierarchy of
I have a number of tables to store different product types in my database
Say I have an online store wherein each product has a single category (and
I have a set of categories for a MySQL database that wont change much,
Here's the table structure table : user id name email category table 2 :
I am designing a database that contains questions, answers and categories. One question can
We are building a Rails CMS where a blog or news listing can appear
I started using NHibernate today, but I cannot figure out how I setup a
i am building a real estate application where in it will store the properties
I am trying to create an exact mirror of a Magento production server on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.