You can't specify target table 'amp_livecollect' for update in FROM clause
时间: 2023-12-25 20:03:37 浏览: 101
This error occurs when you try to update a table that is also used in the subquery used to generate the update. MySQL does not allow this because it can cause conflicts with the data being updated.
To resolve this error, you can use a temporary table to store the results of the subquery and then perform the update on the main table using the temporary table. Here's an example:
```
CREATE TEMPORARY TABLE temp_livecollect
SELECT * FROM amp_livecollect WHERE <condition>;
UPDATE amp_livecollect
SET column1 = value1, column2 = value2
WHERE id IN (SELECT id FROM temp_livecollect);
DROP TEMPORARY TABLE temp_livecollect;
```
In this example, the subquery is stored in a temporary table called `temp_livecollect`. The update is then performed on the main table `amp_livecollect` using the `IN` operator to match the IDs in the temporary table. Finally, the temporary table is dropped to free up resources.
阅读全文