版权声明:欢迎评论和转载,转载时请注明作者和出处,共同维护良好的版权和知识产权秩序。 https://blog.csdn.net/CrazyOnes/article/details/84142590
在另一篇MySQL报错的文章 [Err] 1093 - You can't specify target table 'a' for update in FROM clause (MYSQL报错) 中提到了要将查询结果作为一个表来进行一次select查询
代码如下
update archives a, sys_user s
set s.username = a.stu_name
where s.id = a.id and a.phone IN (select * from (select a.phone
from archives a, sys_user s
where a.phone = s.mobile
GROUP BY a.phone
HAVING COUNT(*) > 1))
和最终的正确代码相比
update archives a, sys_user s
set s.username = a.stu_name
where s.id = a.id and a.phone IN (select * from (select a.phone
from archives a, sys_user s
where a.phone = s.mobile
GROUP BY a.phone
HAVING COUNT(*) > 1) k)
缺少了最后将查询结果命名为表k的过程
所以产生了错误[Err] 1248 - Every derived table must have its own alias
解决方法也很简单,就像上边提到的对查询结果进行一个表命名就可以了。
如有错误,欢迎指摘。也欢迎通过左上角的“向TA提问”按钮问我问题,我将竭力解答你的疑惑。