查询数据库中重复记录的方法

select * from [DataBase].[dbo].[TableName]
where [字段一] in (select [字段一] from [DataBase].[dbo].[TableName]  group by [字段一] having count([字段一]) > 1)

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 peopleId in (select  peopleId from people group by  peopleId  having count(peopleId) > 1)
and rowid not in (select min(rowid) from  people group by peopleId having count(peopleId
)>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)

查询数据库中重复记录的方法

时间: 2024-10-02 17:20:41

查询数据库中重复记录的方法的相关文章

MySQL中查询、删除重复记录的方法大全

前言 本文主要给大家介绍了关于MySQL中查询.删除重复记录的方法,分享出来供大家参考学习,下面来看看详细的介绍: 查找所有重复标题的记录: ? 1 select title,count(*) as count from user_table group by title having count>1; ? 1 SELECT * FROM t_info a WHERE ((SELECT COUNT(*) FROM t_info WHERE Title = a.Title) > 1) ORDER

查询及删除重复记录的方法

1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断select * from peoplewhere peopleId in (select  peopleId  from  people  group  by  peopleId  having  count(peopleId) > 1) 2.删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录delete from people where peopleId  in (

查询数据库中各个类型的方法名称

select name from sysobjects where xtype='TR' --所有触发器select name from sysobjects where xtype='P' --所有存储过程select name from sysobjects where xtype='V' --所有视图select name from sysobjects where xtype='U' --所有表 以上为SqlServer用法 Select object_name From user_ob

Sql Server删除数据表中重复记录 三种方法

本文介绍了Sql Server数据库中删除数据表中重复记录的方法. [项目]数据库中users表,包含u_name,u_pwd两个字段,其中u_name存在重复项,现在要实现把重复的项删除![分析]1.生成一张临时表new_users,表结构与users表一样:2.对users表按id做一个循环,每从users表中读出一个条记录,判断new_users中是否存在有相同的u_name,如果没有,则把它插入新表:如果已经有了相同的项,则忽略此条记录:3.把users表改为其它的名称,把new_use

查找数据库中重复数据T-SQL

查找数据库中重复数据T-SQL ========第一篇========= 在一张表中某个字段下面有重复记录,有很多方法,但是有一个方法,是比较高效的,如下语句: select data_guid from adam_entity_datas a where a.rowid > (select min(b.rowid) from adam_entity_datas b where b.data_guid = a.data_guid) 如果表中有大量数据,但是重复数据比较少,那么可以用下面的语句提高

查询数据库中所有表的记录数,所占空间,索引使用空间

常用 --查询数据库中所有表的记录数,所占空间,索引使用空间 exec sp_MSForEachTable @precommand=N'create table ##(表名 sysname,记录数 int,保留空间 Nvarchar(20),使用空间 varchar(20),索引使用空间 varchar(20),未用空间 varchar(20))', @command1=N'insert ## exec sp_spaceused ''?''', @postcommand=N'select * f

查询数据库中某一列有没有重复数据项

查询数据库中某一列有没有重复数据项: select * from cd_stock where stock_bh in (select stock_bh from cd_stock group by stock_bh having count(stock_bh) >1 ) select * from cd_stock_item where id in (select id from cd_stock_item group by id having count(id) >1 ) 原文地址:htt

ORACLE查询并删除重复记录

查询及删除重复记录的SQL语句 1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断select * from peoplewhere peopleId in (select   peopleId from   people group by   peopleId having count(peopleId) > 1) 2.删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录delete from people where

oracle分页查询结果集重复问题&解决方法

做项目时,无意间发现了分页上的一个bug,在此记录一下: 首先手动将后台输出的sql语句复制进oracle中查看,以便排查错误,对比以下视图前10条的结果集与10到20条的结果集,发现大部分记录出现重复现象,SQL语句如下: --前10条记录 select *   from (select row_.*, rownum rownum_           from (select t.idcard, count(1)                   from sampling.v_unvou