错误代码:1093。您无法在FROM子句中指定目标表'tbl1'进行更新(删除查询)

时间:2016-01-08 12:10:49

标签: mysql

尝试删除某些条件但MySQL抛出错误的记录:   Error Code: 1093

delete from tbl1
where date(cast(traptime as datetime))< date_sub(current_date, interval 200  day) and 
id not in (select max(id) as id from tbl1 group by device_name);

2 个答案:

答案 0 :(得分:1)

试试这个:

DELETE FROM tbl1
WHERE id NOT IN (
    SELECT id FROM (
        select max(id) as id from tbl1 group by device_name
    ) AS c
)
and date(cast(traptime as datetime))< date_sub(current_date, interval 200  day)

答案 1 :(得分:0)

在MySQL中,您无法修改在SELECT部分​​中使用的同一个表。在这里看到答案: MySQL Error 1093 - Can't specify target table for update in FROM clause