1093 - You can't specify target table 'pj_grpjb' for update in FROM clause, Time: 0.079000s
时间: 2024-03-08 21:42:13 浏览: 132
以下是解决1093错误的方法:
1. 使用临时表进行查询结果转化
```sql
UPDATE go_order_pj
SET project_code = '02'
WHERE go_order_pj_id IN
(
SELECT * FROM
(
SELECT go_order_pj_id
FROM go_order_pj
WHERE go_order_id IN
(
SELECT go_order_id
FROM go_order
WHERE org_id = '6482277243980976128'
)
) AS temp_table
);
```
2. 使用连接(JOIN)进行更新
```sql
UPDATE go_order_pj
JOIN go_order ON go_order_pj.go_order_id = go_order.go_order_id
SET go_order_pj.project_code = '02'
WHERE go_order.org_id = '6482277243980976128';
```
相关问题
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.
delete from erp_raw_data_202305 where id in (select id from erp_raw_data_202305 where djh not in (select djh from erp_detail_raw_data_202305 GROUP BY djh)) > 1093 - You can't specify target table 'erp_raw_data_202305' for update in FROM clause > 时间: 0.009s
这是一个MySQL的错误提示,意思是不能在FROM子句中指定要更新的目标表。通常情况下,MySQL不允许在一个语句中同时查询和更新同一个表。
解决这个问题的方法是使用临时表,将要更新的数据先查询出来放到临时表中,然后再更新原表。具体的SQL语句如下:
```
CREATE TEMPORARY TABLE temp_table
SELECT id FROM erp_raw_data_202305
WHERE djh NOT IN (SELECT djh FROM erp_detail_raw_data_202305 GROUP BY djh);
DELETE FROM erp_raw_data_202305
WHERE id IN (SELECT id FROM temp_table);
DROP TEMPORARY TABLE temp_table;
```
这样就可以避免在FROM子句中指定要更新的目标表的问题了。
阅读全文