How to delete old entries based on MAX(id) after an INSERT query?
CREATE TABLE temp LIKE real;
load up `temp`
copy 'last' from real into temp  (why??)
RENAME TABLE real TO old,
             temp TO real;
DROP TABLE old;


Depending on the size of the table, this could be a lot faster than using DELETE.  Also, the table is never not there.

No 'transaction' is needed.