【问题标题】:Mysql error:1093 - Can't specify target table for update in FROM clauseMysql 错误:1093 - 无法在 FROM 子句中指定要更新的目标表
【发布时间】:2014-07-19 14:15:18
【问题描述】:

我的数据库中有一张表employees,其中包含损坏的条目。

我试图删除它们执行:

delete from employees 
where id_boss= (
select id_worker from employees e
where surname= 'XXX')
AND basic_wage>1500

但我得到下一个错误:

#1093 - 您不能在 FROM 子句中指定目标表 'pracownicy' 进行更新

我该如何克服这个问题?

【问题讨论】:

标签: mysql subquery mysql-error-1093


【解决方案1】:

在 MySQL 中,您不能同时从您选择的行中删除。为了克服这个问题,你可以使用另一个子查询来隐藏这个事实,或者你可以把它变成这样的连接

delete e_emp
from employees e_emp
join employees e_boss on e_boss.id_worker = e_emp.id_boss 
where e_boss.surname = 'XXX'
AND e_emp.basic_wage > 1500

【讨论】:

    【解决方案2】:

    它也正确吗? 因为它有效

    DELETE e_emp FROM  employees e_emp, 
    (SELECT id_boss FROM employees  WHERE surname='XXX') AS e_boss
    WHERE e_emp.id_boss=e_boss.id_worker
    AND e_emp.basic_wage>1500
    

    【讨论】:

      猜你喜欢
      • 2013-01-17
      • 2020-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-07
      • 2021-08-15
      • 2014-07-31
      • 2012-07-29
      相关资源
      最近更新 更多