简体   繁体   English

SQL-#1093-表''被指定两次,既作为'UPDATE'的目标又作为数据的单独来源

[英]SQL - #1093 - Table '' is specified twice, both as a target for 'UPDATE' and as a separate source for data

I have this code: 我有以下代码:

UPDATE WORLD_TEST 
SET PROGRAMMER = (SELECT (RECURSE_HOUR/360) 
                  FROM WORLD_TEST_PROGRAMMER, WORLD_TEST 
                  WHERE LVL = LVL_PROGRAMMER) 
WHERE (SELECT MAX_RECURSE 
       FROM WORLD_TEST_PROGRAMMER, WORLD_TEST 
       WHERE LVL = LVL_PROGRAMMER) 
>= 
(PROGRAMMER+(SELECT (RECURSE_HOUR/360) 
             FROM WORLD_TEST_PROGRAMMER, WORLD_TEST 
             WHERE LVL = LVL_PROGRAMMER));

With this error: 出现此错误:

1093 - Table 'WORLD_TEST' is specified twice, both as a target for 'UPDATE' and as a separate source for data 1093-表'WORLD_TEST'被指定两次,既作为'UPDATE'的目标,又作为数据的单独源

EDIT (clarification from comments): PROGRAMMER and LVL_PROGRAMMER is from WORLD_TEST table, and RECURSE_HOUR , LVL , MAX_RECURSE is from WORLD_TEST_PROGRAMMER table. 编辑(从注释中澄清): PROGRAMMERLVL_PROGRAMMER来自WORLD_TEST表,而RECURSE_HOURLVLMAX_RECURSE来自WORLD_TEST_PROGRAMMER表。

Error message is quite clear, that you cannot use the same table in the UPDATE clause as well as the source of a subquery. 错误消息非常清楚,您不能在UPDATE子句中使用同一表以及子查询的源。 There are other ways to achieve that, like using Derived Tables, etc. In this particular case, you simply need to JOIN between the two tables. 还有其他方法可以实现此目的,例如使用派生表等。在这种特定情况下,您只需要在两个表之间进行JOIN

Also, please don't use Old comma based Implicit joins and switch to Modern Explicit Join based syntax 另外,请不要使用基于旧逗号的隐式连接,而不要使用基于现代显式Join的语法

In case of multi-table queries, it is recommended to use Aliasing for code readability and avoiding ambiguous behavior. 对于多表查询,建议使用别名来提高代码的可读性并避免歧义行为。

Based on your further clarification in the comments , try the following: 根据您在评论中的进一步说明,尝试以下操作:

UPDATE WORLD_TEST AS wt 
JOIN WORLD_TEST_PROGRAMMER AS wtp 
  ON wt.LVL_PROGRAMMER = wtp.LVL 
SET wt.PROGRAMMER = wtp.RECURSE_HOUR
WHERE wtp.MAX_RECURSE >= (wt.PROGRAMMER + (wtp.RECURSE_HOUR/360))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误代码:1093表“事务”被指定两次,既作为“更新”的目标,又作为数据的单独源 - Error Code: 1093 Table 'transactions' is specified twice, both as a target for 'UPDATE' and as a separate source for data 错误代码:1093。表'site_html'被指定两次,既作为'UPDATE'的目标又作为数据的单独来源 - Error Code: 1093. Table 'site_html' is specified twice, both as a target for 'UPDATE' and as a separate source for data #1093-表'filtros'被指定两次,既作为'UPDATE'的目标,又作为数据的单独源 - #1093 - Table 'filtros' is specified twice, both as a target for 'UPDATE' and as a separate source for data 表名称指定两次作为更新目标和单独的数据源 - Table name specified twice both as a target for update and separate source for data 表被指定两次,既作为 'UPDATE' 的目标,也作为单独的数据源 - Table is specified twice, both as a target for 'UPDATE' and as a separate source for data 表被指定两次,既作为'UPDATE'的目标,又作为单独的数据源 - Table is specified twice, both as a target for 'UPDATE' and as a separate source for data MySQL-表两次指定为更新目标和单独数据源 - MySQL - table specified twice both as a target for update and as a separate source for data 表名指定两次,既作为更新的目标,又作为单独的数据源 - Table name specified twice, both as a target for update and as a separate source for data 表被指定两次,既作为 'UPDATE' 的目标,也作为 mysql 中数据的单独源 - Table is specified twice, both as a target for 'UPDATE' and as a separate source for data in mysql java.sql.SQLException:表被指定了两次,既作为“更新”的目标,又作为数据的单独源 - java.sql.SQLException: Table is specified twice, both as a target for 'UPDATE' and as a separate source for data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM