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.