MySQL update 链表 (一个表数据当做条件错误时候的转换)

MySQL语句一:

UPDATE lesson_p set solve_status = 6 where lesson_p_id in (SELECT lp.lesson_p_id FROM `lesson_p` lp LEFT JOIN jx_lesson_p_after jpa ON lp.lesson_p_id = jpa.lesson_p_id where lp.lesson_type = 2 and lp.solve_status = 5 and jpa.mark = 1 and jpa.operate_period = 3
and lp.plan_start_time > '2018-3-1 00:00:00' and lp.plan_start_time < '2019-03-12 15:39:04');

[Err] 1093 - You can't specify target table 'lesson_plan' for update in FROM clause

转化

MySQL语句二:

UPDATE lesson_p lp LEFT JOIN jx_lesson_p_after jpa ON lp.lesson_p_id = jpa.lesson_p_id set lp.solve_status = 6 WHERE lp.lesson_type = 2 and lp.solve_status = 5 and jpa.mark = 1 and jpa.operate_period = 3
and lp.plan_start_time > '2018-3-1 00:00:00' and lp.plan_start_time < '2019-03-12 15:39:04'

成功

原文地址:https://www.cnblogs.com/songyanan/p/10518825.html