You can’t specify target table ‘表名’ for update in FROM clause
意思是 不能先select出同一表中的某些值,再update这个表
原SQL语句:
update
push_to_cloud
set
is_confirm = 1 , direction = 1
where
student_code = 01
and
`snap_time`= (
select max(`snap_time`)from push_to_cloud
)
出现这种情况,只需要通过中间表select一遍就可以了。
解决办法:
update
push_to_cloud
set
is_confirm=1,direction=1
WHERE
student_code = 01
and
`snap_time` =(
select a.time from (
select MAX(snap_time) time from push_to_cloud
) a
)
如果出现
Every derived table must have its own alias
检查是不是没有给表取别名
本文解决了一个常见的MySQL更新语句错误:“You can't specify target table for update in FROM clause”。通过引入子查询和别名的方式,避免了在同一更新语句中直接引用目标表的问题,成功更新了表中的特定记录。

8591

被折叠的 条评论
为什么被折叠?



