无法指定目标表进行更新,在mysql中删除查询
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错误。上述请求无法回答删除没有唯一键的重复行的问题。
更多相关文章
- You can't specify target table 'compares' for up
- 【错误】:MySql Host is blocked because of many connection err
- mysql 服务意外停止1067错误解决办法小结
- Ruby 1.9 + MySQL中发生访问错误
- 错误'未知表引擎'InnoDB''查询。重启mysql后
- MySQL“在建立到SQL Server的连接时发生与网络相关或特定于实例
- MySQL数据库表名、列名、别名区分大小写的问题
- 尝试将纬度和经度发布到数据库时,Android JSON解析错误
- 语法错误:从[{id}]开始的表达式[{id}]第2列的令牌'{'无效键?