www.fltk.net > MYSQL删除重复记录保留一条,应该如何操作.

MYSQL删除重复记录保留一条,应该如何操作.

例如: id name value 1 a pp 2 a pp 3 b iii 4 b pp 5 b pp 6 c pp 7 c pp 8 c iii id是主键 要求得到这样的结果 id name value 1 a pp 3 b iii 4 b pp 6 c pp 8 c iii 方法1 delete YourTable where [id] not in ( select max([id]) from Your...

换个思路, 你再新建一个表,表里的字段跟你这个表的字段一样。。 然后 insert into select from 。。。。这里你应该懂了吧,, 就是去重查询之后,然后将结果集插入到指定的表中。。

delete from `mygame_article` where title in (select title from `mygame_article` group by id having count(title) > 1) and id not in (select max(id) from `mygame_article` group by title having count(title) > 1); 随手写了个,前半...

delete from temp where id in (select id from (select max(id) as id,count(url) as count from temp group by url having count >1 order by count desc) as tab )

列出要保留的记录ID,可以把这个结果写到一个临时表t1中: SELECT MAX(id) AS max_id FROM pedigree GROUP BY number 然后:DELETE FROM pedigree WHERE id NOT IN (SELECT id FROM t1) 也就是:delete from pedigree where id not in(select * ...

删除重复行sql,将会删除所用重复的数据,保留一条不重复的数据 ALTER IGNORE TABLE your_tableADD UNIQUE INDEX idx_name (cols_a, cols_b, cols_c, cols_d, cols_e);

select * FROM product p1 WHERE p1.pid in ( SELECT MIN(p2.pid) FROM product p2 group by pname having count(*)>1 ); 先用这个语句看一下是不是对的 再把select * 改为delete

可以先使用去重的查询将数据导入到临时表, 然后备份并清理当前表, 再把数据从临时表导回来

应该是这么写的,你备份数据之后试试 delete from cars where id not in( select id from (select id,max(pici) from cars group by xinghao)a )

假如我有一张表, 数据在某一个字段有重复(比如我现在的ID重复了) 那么我使用: SELECT id,COUNT(*) FROM table GROUP BY id HAVING COUNT(*) > 1; 语句 意思: 从读下来是 查询id,并且统计行数 数据来自 table表 按照id列进行分组(如果我们...

网站地图

All rights reserved Powered by www.fltk.net

copyright ©right 2010-2021。
www.fltk.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com