1

Trying to delete records with some conditions but MySQL throwing error: 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);
Abhishek Ginani
  • 4,511
  • 4
  • 23
  • 35

2 Answers2

1

Try this:

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)
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
0

In MySQL, you can't modify the same table which you use in the SELECT part. See answer here: MySQL Error 1093 - Can't specify target table for update in FROM clause

Community
  • 1
  • 1
  • If the answer is in another question, just flag it as a duplicate, don't post a link-only answer. – Barmar Jan 08 '16 at 13:10