sql DELETE FROM t_project_disclose WHERE id IN ( SELECT tpd.id FROM t_project_disclose tpd WHERE tpd.project_plan_id NOT IN ( SELECT opp.ID FROM t_project_disclose tpd JOIN overhaul_project_plan opp ON tpd.project_plan_id = opp.ID ) AND tpd.version_id = 'd2576fc1e2be4258ac8b624b926cc44c'); 报以下错误 You can't specify target table 't_project_disclose' for update in FROM clause
时间: 2024-03-06 17:50:58 浏览: 67
这个错误是因为 MySQL 不支持在一个子查询中更新和查询同一个表。
为了解决这个问题,可以使用临时表或者多层嵌套查询来代替子查询。以下是使用多层嵌套查询的示例 SQL 语句:
```
DELETE FROM t_project_disclose WHERE id IN (
SELECT id FROM (
SELECT tpd.id FROM t_project_disclose tpd
WHERE tpd.project_plan_id NOT IN (
SELECT opp.ID FROM t_project_disclose tpd
JOIN overhaul_project_plan opp ON tpd.project_plan_id = opp.ID
)
AND tpd.version_id = 'd2576fc1e2be4258ac8b624b926cc44c'
) AS tmp
);
```
在这个 SQL 语句中,首先使用了一个 SELECT 语句来获取需要删除的数据的 id,然后将其放入一个临时表 tmp 中,最后使用 DELETE 语句将临时表中的数据从表 `t_project_disclose` 中删除。
请注意,如果数据量很大,使用多层嵌套查询可能会导致性能问题,此时可以考虑使用临时表来解决。
相关问题
根据id删除 该sql的查询结果 select * from t_project_disclose tpd where tpd.id in ( select tpd.id from t_project_disclose tpd where tpd.project_plan_id not in ( select opp.ID from t_project_disclose tpd join overhaul_project_plan opp on tpd.project_plan_id = opp.ID ) and tpd.version_id = 'd2576fc1e2be4258ac8b624b926cc44c');
根据您提供的 SQL 查询语句,可以使用以下 SQL 语句来根据 id 删除查询结果中的数据:
```
DELETE FROM t_project_disclose WHERE id IN (
SELECT tpd.id FROM t_project_disclose tpd
WHERE tpd.project_plan_id NOT IN (
SELECT opp.ID FROM t_project_disclose tpd
JOIN overhaul_project_plan opp ON tpd.project_plan_id = opp.ID
)
AND tpd.version_id = 'd2576fc1e2be4258ac8b624b926cc44c'
);
```
上述 SQL 语句中,使用了嵌套的 SELECT 语句来获取需要删除的数据的 id,然后使用 DELETE 语句将其从表 `t_project_disclose` 中删除。其中,子查询的条件与原查询语句相同,即 `tpd.project_plan_id NOT IN (SELECT opp.ID FROM t_project_disclose tpd JOIN overhaul_project_plan opp ON tpd.project_plan_id = opp.ID) AND tpd.version_id = 'd2576fc1e2be4258ac8b624b926cc44c'`。请注意备份数据后再进行删除操作。
Type Status Report Message /shopTest_war_exploded/product/showAllProducts.jsp Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
根据你的问题我看到你遇到了一个 Type Status Report 错误,这个错误通常与 Web 应用程序有关。这个错误提示说目标资源不存在或者原始服务器不愿意公开存在的资源。这个错误可能是由于以下原因导致的:
1. 目标资源不存在或者已被移动
2. 服务器配置不正确
3. 网络连接问题
如果你是网站管理员或者开发者,你应该检查服务器配置和网络连接以确定问题的原因。如果你是普通用户,你可以尝试重新加载页面或者联系网站管理员寻求帮助。
阅读全文