SQL删除重复数据只保留一条

   用SQL语句,删除掉重复项只保留一条

  在几千条记录里,存在着些相同的记录,如何能用SQL语句,删除掉重复的呢

  1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断

  select * from people

  where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)

  2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录

  delete from people

  where peopleName in (select peopleName from people group by peopleName having count(peopleName) > 1)

  and peopleId not in (select min(peopleId) from people group by peopleName having count(peopleName)>1)

  3、查找表中多余的重复记录(多个字段)

  select * from vitae a

  where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)

  4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录

  delete from vitae a

  where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)

  and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)

  5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录

  select * from vitae a

  where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)

  and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)

  6.消除一个字段的左边的第一位:

  update tableName set [Title]=Right([Title],(len([Title])-1)) where Title like '村%'

  7.消除一个字段的右边的第一位:

  update tableName set [Title]=left([Title],(len([Title])-1)) where Title like '%村'

  8.假删除表中多余的重复记录(多个字段),不包含rowid最小的记录

  update vitae set ispass=-1

  where peopleId in (select peopleId from vitae group by peopleId

时间: 2024-10-26 22:08:26

SQL删除重复数据只保留一条的相关文章

select-Mysql删除重复数据只保留一条

问题描述 Mysql删除重复数据只保留一条 Mysql删除重复数据只保留一条,我的sql这样的 DELETE from t_patient WHERE pa_iid IN (select pa_iid from t_patient group by pa_vname having count(pa_vname)>1) 但是报错了: [Err] 1093 - You can't specify target table 't_patient' for update in FROM clause 求

oracle删除重复数据只保留一条

重复的数据可能有这样两种情况,第一种: 表中只有某些字段一样,第二种是两行记录完全一样. 一.对于部分字段重复数据的删除 1.查询重复的数据 select 字段1,字段2, count(*) from 表名 group by 字段1,字段2 having count(*) > 1 例:Select owner from dba_tables group by owner having count(*)>1; Select owner from dba_tables group by owner

JS数组去掉重复数据只保留一条的实现代码_javascript技巧

非常不多说,js数组去掉重复数据的代码如下所示: var arr = [1,2,3,4,5,6,1,6,7,2]; var newArr = []; for(var i =0;i<arr.length-1;i++){ if(newArr.indexOf(arr[i]) == -1){ newArr.push(arr[i]); } } 下面再给大家分享高效率去掉js数组中重复项 Array类型并没有提供去重复的方法,如果要把数组的重复元素干掉,那得自己想办法: function unique(ar

解决Oracle删除重复数据只留一条的方法详解_oracle

查询及删除重复记录的SQL语句1.查找表中多余的重复记录,重复记录是根据单个字段(Id)来判断select * from 表 where  Id in (select Id from 表 group by Id having count(Id) > 1) 2.删除表中多余的重复记录,重复记录是根据单个字段(Id)来判断,只留有rowid最小的记录DELETE from 表 WHERE (id) IN ( SELECT id FROM 表 GROUP BY id HAVING COUNT(id)

sql删除重复数据的详细方法_MsSql

一. 删除完全重复的记录 完全重复的数据,通常是由于没有设置主键/唯一键约束导致的.测试数据: 复制代码 代码如下: if OBJECT_ID('duplicate_all') is not nulldrop table duplicate_all GO create table duplicate_all ( c1 int, c2 int, c3 varchar(100) ) GO insert into duplicate_all select 1,100,'aaa' union allse

用SQL语句,删除掉重复项只保留一条

原文 用SQL语句,删除掉重复项只保留一条 在几千条记录里,存在着些相同的记录,如何能用SQL语句,删除掉重复的呢 1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断 select * from people where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1) 2.删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,

SQL删除重复数据方法

原文:SQL删除重复数据方法 例如: id           name         value 1               a                 pp 2               a                 pp 3               b                 iii 4               b                 pp 5               b                 pp 6            

sql 删除重复数据

sql 删除重复数据 本文章提供一款mysql删除重复数据,就是数据表中存在二条以上的重复数据,删除编号最小的一条信息. delete `borough_name` as a from fke_borough as a, ( select *,min(id) from fke_borough group by `borough_name` having count(1) > 1 ) as b  where a.`borough_name` = b.`borough_name` and a.id

mysql 数据表合并并且只重复数据只读取一条

mysql教程 数据表合并并且只重复数据只读取一条 //首先我们来盾mysql sql结构了,用了union联合查询与insert into 来整表复制了. mysql_connect("localhost","root","root") or die('Database Server Uid or Password Error!'); mysql_select_db('ip') or die('data !'); mysql_query(&qu