MySQL 删除表中重复的记录(where......)
来源:互联网 发布:ubuntu复制目录命令 编辑:程序博客网 时间:2024/04/27 17:48
delete from at1 where id in (select * from (select max(id) from at1 group by str having count(str) > 1) as b); or delete a from at1 as a, at1 as b where a.str=b.str and a.id > b.id; 3. 多个字段重复的问题。 “name”值存在重复的项; Select Name,Count(*) From A Group By Name Having Count(*) > 1 (见http://hi.baidu.com/yangjifu/blog/item/723e5f4cf92708ffd72afc92.html) ----------------------------------------- 1.MySQL的delete 支持: DELETE t1,t2 FROM t1,t2,t3 WHERE t1.id=t2.id AND t2.id=t3.id 2. 从 MySQL 4.0.4 开始,你也可以执行一个包含多个表的 UPDATE 的操作: 3. 查询一个表中重复的记录: select max(id) from at1 group by str having count(str) > 1 select a.id from at1 as a, at1 as b where a.str=b.str and a.id > b.id 4. delete from at1 where id in (select max(id) from at1 group by str having count(str) > 1); 是错误的: ERROR 1093 : You can't specify target table 'at1' for update in FROM clause 正确写法:delete from at1 where id in (select * from (select max(id) from at1 group by str having count(str) > 1) as b); 理由(文档): In general, you cannot modify a table and select from the same table in a subquery. For example, this limitation applies to statements of the following forms: DELETE FROM t WHERE ... (SELECT ... FROM t ...);UPDATE t ... WHERE col = (SELECT ... FROM t ...);{INSERT|REPLACE} INTO t (SELECT ... FROM t ...); Exception: The preceding prohibition does not apply if you are using a subquery for the modified table in the UPDATE t ... WHERE col = (SELECT (SELECT ... FROM t...) AS _t ...); Here the prohibition does not apply because a subquery in the mysql还支持 where (a,b) in (select a, b from aaaa) |
- MySQL 删除表中重复的记录(where......)
- MySQL 删除表中重复的记录(where......)
- 删除mysql 表中重复的记录
- MYSQL中删除重复记录的方法
- MYSQL中删除重复记录的方法
- MYSQL中删除重复记录的方法
- Mysql中删除重复记录的方法
- MYSQL中删除重复记录的方法
- MYSQL中删除重复记录的方法
- MYSQL中删除重复记录的方法
- MYSQL中删除重复记录的方法
- MYSQL 删除同一表中重复记录
- mysql 删除表中重复记录
- mysql 删除数据库表中重复记录
- MySQL 删除表中重复记录
- MySQL中删除重复记录
- 删除MySQL表的重复记录
- MySql删除重复的记录
- 其它与 pymssql 有关的软件包
- 第一次出马买股票
- JavaScript函数_eval()
- [代码]无DLL远程线程注入得到目标程序的星号密码
- Configuring Solaris ACPI at boot-time
- MySQL 删除表中重复的记录(where......)
- static_cast
- 安装Mysql-python-1.2.2的依赖包
- 面向对象设计的基本原则
- 一个女人究竟该花多少钱?
- linux export问题
- Tomcat报告——Tomcat中SSI的配置
- 有效的工作分解结构 笔记
- 在SQL Server 2005中使用OUTPUT完成数据操作时的备份