[Err] 1093 - You can’t specify target table ‘product’ for update in FROM clause
原因: 不能先select再update。 update product set putaway = ‘已上架’ where id in ( select t.id from product t where t.putSet = ‘定时上架’ and t.putaway = ‘待上架’ and t.putTime <= NOW() )
解决方法: 参考 – 使用left join 改写 update x left join x xx on x.id = xx.id and xx.additional_info = 1 set available_material_id = null where xx.id is null;
使用left join。 update product p left join product t on p.id = t.id set p.putaway = ‘已上架’ where t.putSet = ‘定时上架’ and t.putaway = ‘待上架’ and t.putTime <= NOW()