查找和删除记录中有多个字段重复的记录的sql语句怎么写
查找和删除记录中有多个字段重复的记录的sql语句怎么写?网上搜了,都是同一个文章,那个语句报错。
这是网上找的:3、查找表中多余的重复记录(多个字段)
select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
报错:消息 102,级别 15,状态 1,第 2 行
',' 附近有语法错误。
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)
报错:消息 102,级别 15,状态 1,第 1 行
'a' 附近有语法错误。
消息 156,级别 15,状态 1,第 3 行
关键字 'and' 附近有语法错误。
------解决方案--------------------查询有点问题,会少数据。更正下。
select a.* from vitae as a join
(select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)as t
on a.peopleid=t.peopleid and a.seq=t.seq