
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 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 awhere (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having
扩展资料
FROM子句指定SELECT语句查询及与查询相关的表或视图。在FROM子句中最多可指定256个表或视图,它们之间用逗号分隔。
在FROM子句同时指定多个表或视图时,如果选择列表中存在同名列,这时应使用对象名限定这些列所属的表或视图。
例如在usertable和citytable表中同时存在cityid列,在查询两个表中的cityid时应使用下面语句格式加以限定:
SELECTusername,citytable.cityid
FROMusertable,citytable
WHEREusertable.cityid=citytable.cityid
在FROM子句中可用以下两种格式为表或视图指定别名:
表名 as 别名
表名 别名
参考资料:百度百科 SELECT语句
1、在电脑上打开要去掉重复数据的数据库,这里新建一张含有重复数据的user表。
2、输入“select * from user where name in (select name from user group by name having count(name) >1) ”sql语句,点击运行可以看到查询出了数据库中user表的重复数据。
3、通过“delete from user where name in (select name from user group by name having count(name) >1) ”sql语句删除姓名重复的数据。
4、也可以通过“select distinct name from user”sql语句来去掉重复数据,这里去掉了张三的重复数据。
5、通过“select distinct class from user”sql语句来去掉班级相同的重复数据。
方法如下:select * from 你的表名
a where id=(select min(id) from 你的表名 whereitem_id=a.item_id)
在查询之前先把数据库表中的第一行复制到sid里在去,然后让sid和下面的每一行进行比较
取所有相同的行的最小的一下,也可以取最大的,结果是一样的。
这样让所有的行都比较不就得到不重复的数据了。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)