问题描述:在执行mysql数据库更新操作时,出现错误提示:
You can’t specify target table ‘student’ for update in FROM clause(你不能在FROM子句中指定目标表’student’进行更新)
mysql> update student set tel = null where
-> entime = (select MAX(entime) from student )
-> or
-> birthday = (select MAX(birthday) from student);
ERROR 1093 (HY000): You can't specify target table 'student' for update in FROM clause
解决方法:
使用临时表替代查询的表:
mysql> update student set tel = null where
-> entime = (select a1.entime from (select MAX(entime) as entime from student) as a1)
-> or
-> birthday = (select a2.birthday from (select MAX(birthday) as birthday from student) as a2)
-> ;
Query OK, 7 rows affected (0.01 sec)
Rows matched: 7 Changed: 7 Warnings: 0