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

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

数据量不是很大的话可以用这个: select * from 表名 where id not in (select m.id from (select min(id) id from 表名 group by phone)m) 把表名换成你这个的表名

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); 随手写了个,前半...

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

起初表不应该这样设计 至少得有个主键吧 记录完全重复 囧 mysql code: create table tmp select distinct * from mytable; drop table mytable; create table mytable select * from tmp; drop table tmp;

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 )

难倒只能分步操作,蛋疼 以下是网友写的,同样是坑爹的代码,我机器上运行不了。 1. 查询需要删除的记录,会保留一条记录。 ? 1 select a.id,a.subject,a.RECEIVER from test1 a left join (select c.subject,c.RECEIVER ,max(c.id) as bid from...

只能用变通的办法 假设表有N1,N2,N3三个字段,都是INT类型,表名是NUMBER,执行如下语句: DECLARE @TB TABLE (N1 INT,N2 INT,N3 INT); INSERT INTO @TB SELECT TOP 1 * FROM NUMBER; DELETE NUMBER; INSERT INTO NUMBER SELECT * FROM @TB; SELE...

你不能在同一个表上做更新操作 需要给查询出的数据集再查询一次

你的字段都没搞出来,怎么啊,我假如你只有三个字段,一个ID,一个column1,column2吧: Delete From table where ID not in (Select min(iD) From Table group by column1,column2) --有多少个字段,group by 后面加多少个,ID除外

代码如下: select * from tbl_DPImg where ID in (select min(ID) from tbl_DPImg group by DPID)处理后结果为: 查找表中多余的重复记录,重复记录是根据单个字段(teamId)来判断 select * from team where teamId in (select teamId from tea...

网站地图

All rights reserved Powered by www.fltk.net

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