SELECT AID,BID,……
FROM T1
WHERE NOT EXISTS (SELECT 1 FROM T AID=T1.AID AND BID=T1.BID)
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)
用group by语句可以筛选重复数据。
1、创建测试表、插入数据
create table test(id int,
name varchar(10))
insert into test values (1,'张三')
insert into test values (2,'李四')
insert into test values (3,'王五')
insert into test values (4,'赵六')
insert into test values (1,'张三')
insert into test values (2,'李四')
2、现在要筛选出重复数据,使查询的数据不重复,可用语句
select id,name from test group by id,name
3、结果如图:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)