I want to do what seems like a simple delete in mysql but am having some trouble. I want to do this:

我想在mysql中做一个简单的删除但是遇到麻烦。我想做这个:

delete from table where col_name not in (select distinct col_name from table);

This table does not have a unique key. When I try this, I get the error:

此表没有唯一键。当我尝试这个时,我得到错误:

You can't specify target table for update in from clause; ErrorNr. 1093

您不能在from子句中指定update的目标表; ErrorNr。 1093

mysql community 5.1

mysql社区5.1

Is there a way i can save the output from this query ->

有没有办法可以保存此查询的输出 - >

select distinct col_name from table;

into temp. table and use it in the delete query?

进入临时表并在删除查询中使用它?

2 个解决方案

#1


3

You must use an alias.

您必须使用别名。

delete from table where col_name not in (select a.col_name from (select distinct col_name from table) a);

It should work.

它应该工作。

Edit : sorry, I misunderstood the question, and only focus on the SQL Error. The probleme to delete duplicate line with no unique key isn't answered by the above request.

编辑:抱歉,我误解了这个问题,只关注SQL错误。上述请求无法回答删除没有唯一键的重复行的问题。

更多相关文章

  1. You can't specify target table 'compares' for up
  2. 【错误】:MySql Host is blocked because of many connection err
  3. mysql 服务意外停止1067错误解决办法小结
  4. Ruby 1.9 + MySQL中发生访问错误
  5. 错误'未知表引擎'InnoDB''查询。重启mysql后
  6. MySQL“在建立到SQL Server的连接时发生与网络相关或特定于实例
  7. MySQL数据库表名、列名、别名区分大小写的问题
  8. 尝试将纬度和经度发布到数据库时,Android JSON解析错误
  9. 语法错误:从[{id}]开始的表达式[{id}]第2列的令牌'{'无效键?

随机推荐

  1. Android Application 之 allowBackup 属
  2. Android之获取Android唯一ID
  3. Android 8.0 权限警告(not in privapp-per
  4. android web
  5. Android:Loader
  6. android toolchain is using Thread mode
  7. android邮件发送几种方式
  8. Android 禁用 APP 或四大组件
  9. Android:Android.bat批处理命令
  10. android Listview相关内容