在MySQL的Table记录中,我有以下内容:
SELECT * FROM dbo.online;
+-------+
| Id |
+-------+
| 10128 |
| 10240 |
| 6576 |
| 32 |
| 10240 |
| 10128 |
| 10128 |
| 12352 |
+-------+
8 rows in set (0.00 sec)
如何进行:
SELECT * FROM dbo.online;
+-------+
| Id |
+-------+
| 10128 |
| 10240 |
| 6576 |
| 32 |
| 12352 |
+-------+
8 rows in set (0.00 sec)
换句话说,我想做的是,使用DELETE命令而不是SELECT * FROM dbo.online GROUP BY id ..所以,任何想法如何?
答案 0 :(得分:2)
使用distinct
将数据复制到备份表,该操作可以消除重复
create table backUp_online as
SELECT distinct *
FROM online;
清除源表
truncate table online
将数据从备份复制到源表而不重复
insert into online
select *
from backUp_online
答案 1 :(得分:1)
答案 2 :(得分:0)
最简单的查询也可以这样做。
DELETE n1 FROM online n1, online n2 WHERE n1.id < n2.id AND n1.name = n2.name