SQL:删除表中重复的记录
发布时间:2020-12-31 00:49:42 所属栏目:MySql教程 来源:网络整理
导读:以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考 --创建测试表if object_id('test') is not null drop table testcreate table test( id int identity(1,1) primary key,name varchar(50))--插入几条测试数据insert
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考 --创建测试表 if object_id('test') is not null drop table test create table test ( id int identity(1,1) primary key,name varchar(50) ) --插入几条测试数据 insert into test select 'a' union all select 'a' union all select 'a' union all select 'a' union all select 'a' union all select 'a' union all select 'b' union all select 'b' union all select 'b' union all select 'b' union all select 'b' union all select 'b' union all select 'b' union all select 'c' union all select 'c' union all select 'c' union all select 'd' union all select 'd' --查看当前记录 select * from test if object_id('#') is not null drop table # --注意(是单个字段的不同还是多个字段,这里是name) select distinct (name) into # from test --查看新表中的数据 select * from # --清空旧表 truncate table test --将新表中的数据插入到旧表 insert test select * from # --删除新表 drop table # --查看结果 select * from test 查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断? 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:PHP编程网 - 黄冈站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |