You can't specify target table 'tmp_inventory_details' for update in FROM clause
时间: 2024-03-08 22:38:58 浏览: 27
"You can't specify target table 'tmp_inventory_details' for update in FROM clause"错误是MySQL中的一个常见错误。这个错误通常发生在使用子查询更新数据时,子查询中引用了更新目标表。解决这个错误的方法是使用临时表来保存子查询的结果,然后再进行更新操作。
以下是解决这个错误的步骤:
1. 创建一个临时表,将子查询的结果保存到临时表中。
2. 使用临时表进行更新操作,而不是直接在子查询中引用更新目标表。
相关问题
You can t specify target table res_device_info for update in FROM clause
This error message usually occurs in SQL when you try to update a table that is also used in the FROM clause of the same query. To resolve this issue, you can use a subquery to update the table instead. Here's an example:
```sql
UPDATE res_device_info
SET column_name = new_value
WHERE device_id IN (
SELECT device_id
FROM res_device_info
WHERE condition
);
```
In this example, you can replace `column_name`, `new_value`, `condition` with the appropriate values for your scenario. Make sure to adjust the subquery's condition to match your requirements.
You can't specify target table 'ec_b_jlss' for update in FROM clause
这个错误通常是因为在MySQL中不能直接在FROM子句中使用相同的表进行更新操作。为了解决这个问题,可以使用子查询或者临时表来解决。下面是两种常见的解决方法:
1. 子查询:
可以将更新操作包装在子查询中,然后使用这个子查询来更新原始表。
例如:
UPDATE ec_b_jlss SET price = price * 0.9 WHERE id IN (SELECT id FROM (SELECT id FROM ec_b_jlss) AS tmp);
2. 临时表:
也可以先将需要更新的数据复制到一个临时表中,然后再通过临时表来更新原始表。
例如:
CREATE TEMPORARY TABLE tmp_table SELECT * FROM ec_b_jlss;
UPDATE tmp_table SET price = price * 0.9;
UPDATE ec_b_jlss SET price = (SELECT price FROM tmp_table WHERE tmp_table.id = ec_b_jlss.id);
DROP TEMPORARY TABLE IF EXISTS tmp_table;
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)