mysql - 更新: You can't specify target table 'table' for update in FROM clause

标签 mysql oracle

我有两个关于 oracle 的查询。我需要为 mysql 修改它们。 第一个查询:

 UPDATE tec_onoff_file a
 SET emailtype = 'MIGR'
 WHERE EXISTS
    (SELECT 1
       FROM tec_onoff_file
       WHERE emailtype = 'MIGR'
       AND a.acctnbr = acctnbr
       AND a.magabbr = magcodes);

我把它改成了

update tec_onoff_file t1
join tec_onoff_file t2
    on t2.emailtype='MIGR'
    and t1.acctnbr=t2.acctnbr
    and t1.magabbr=t2.magcodes
    set t1.emailtype='MIGR';

并且它有效。 但第二个查询对我来说更难

update tec_onoff_file a
set emailtype = 'REIN'
where transtype = 'REIN'
and curracctnbr not in (select curracctnbr from tec_onoff_file b
    where emailtype ='RENW'
    and a.curracctnbr=b.curracctnbr);

有人可以帮忙吗?我正在尝试像第一次使用 JOIN 查询一样更改它,但它失败了,我不知道该怎么做。

最佳答案

UPDATE tec_onoff_file a
  LEFT 
  JOIN tec_onoff_file n
    ON b.curracctnbr = a.curracctnbr 
   AND b.emailtype ='RENW'
   SET emailtype = 'REIN'
 WHERE a.transtype = 'REIN'
   AND b.transtype IS NULL;

关于mysql - 更新: You can't specify target table 'table' for update in FROM clause,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26657375/

相关文章:

php - 添加来自不同表的每一行值

MysqlDump 出现 ShellExecute 错误

sql - PL/SQL 验证/插入/更新状态 - retval 与异常

oracle - 如何使用 node-oracledb 连接到 LDAP 服务器?

javascript - HTML 表格中的 AngularJS

mysql - 语法错误或访问冲突 : 1630 FUNCTION dbparty. DATE_FORMAT 不存在

database - SpagoBI 5.2 不显示保存的数据集。我应该怎么办?

sql - 为什么 Oracle 数据库不适用于 as

xml - 从 Oracle 表在 PL/SQL 中生成 XML 文档

mysql - mysql中的字母数字列自然排序,其中数据是字母、数字、特殊字符的任意组合