zoukankan      html  css  js  c++  java
  • mySQL: delete 语句报错 You can't specify target table 'student' for update in FROM clause

    delete from  student
    where id NOT in (
    select min(id) id from student group by name,stuid,subid,subname,score
    );

    当在mysql中执行这条语句时,报错:You can't specify target table 'student' for update in FROM clause;

    原因是子查询中使用student表进行查询,而外层的delete语句也是对student进行的操作,因此报错。

    解决办法:

    将子查询再包装一次:

    delete from  student
    where id NOT in (
    select * from (
    select min(id) id from student group by name,stuid,subid,subname,score
    )a
    );

    注意:这种错误只出现在mySQL中。

    参考:http://blog.csdn.net/priestmoon/article/details/8016121

    面朝大海,春暖花开。
  • 相关阅读:
    连接数据库
    单行函数
    最小生成树
    hdu 1018
    组合 母函数 hdu 1171
    石子合并
    hdu 1047
    java 小综合
    java 声音处理
    并查集 1213
  • 原文地址:https://www.cnblogs.com/HapLe0/p/7761016.html
Copyright © 2011-2022 走看看