Use "select max" query instead of lastInsertId() on archive table