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

  • SEARCH
  • Home
  • 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 9136737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:59:33+00:00 2026-06-17T08:59:33+00:00

I’m trying to fix an incomplete database where I don’t have control over the

  • 0

I’m trying to fix an incomplete database where I don’t have control over the schema and I need to find missing entries and insert them.

This is syntax I’ve arrived at:

INSERT INTO 
  downloads (product_id, filename)
VALUES 
( 
  products_id = ( SELECT id
         FROM products 
         WHERE id NOT IN
           ( SELECT product_id
             FROM downloads
           )
       ), 
  filename = 'default.zip'
)

The subquery works fine alone but the above throws an error

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

I’ve reviewed many of the StackOverflow questions related to this error (like this), and I gather that there is a way to nest a subquery such that it “creates an implicit temporary table, so it doesn’t count as the same table you’re updating” but I haven’t been able to adapt it.

If my approach is inefficient that’s OK, I’m very curious to see a solution that get’s close to my syntax but any solution would be helpful.

  • 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. Editorial Team
    Editorial Team
    2026-06-17T08:59:33+00:00Added an answer on June 17, 2026 at 8:59 am

    Things to do,

    • use INSERT...INTO SELECT statement
    • use LEFT JOIN instead of NOT IN
    • don’t forget to add index on this columns: products.ID and downloads.product_id for faster performance

    query,

    INSERT INTO  downloads (product_id, filename)
    SELECT  a.id AS product_id, 'default.zip' AS filename
    FROM    products a
            LEFT JOIN downloads b
                ON a.ID = b.product_id
    WHERE   b.product_id IS NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have been unable to fix a problem with Java Unicode and encoding. The
I have thousands of HTML files to process using Groovy/Java and I need to
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a reasonable size flat file database of text documents mostly saved in
I am trying to loop through a bunch of documents I have to put
Let's say I'm outputting a post title and in our database, it's Hello Y’all

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.