You can't specify target table 'cluster_addresses_copy1' for update in FROM clause
时间: 2024-03-08 11:27:33 浏览: 90
This error occurs when you try to update a table that is also used in a subquery that is used in the same query. MySQL does not allow this because it can cause unexpected results or errors.
To fix this error, you can create a temporary table to store the results of the subquery, and then use that table in the update statement. Here is an example:
CREATE TEMPORARY TABLE temp_table
SELECT * FROM cluster_addresses_copy1 WHERE ...
UPDATE cluster_addresses_copy1
SET column1 = value1
WHERE id IN (SELECT id FROM temp_table);
Alternatively, you can use a JOIN instead of a subquery to avoid this error:
UPDATE cluster_addresses_copy1
JOIN (SELECT id FROM cluster_addresses_copy1 WHERE ...) AS temp_table
ON cluster_addresses_copy1.id = temp_table.id
SET column1 = value1;
阅读全文