Sqlserver_ Delete duplicate rows keep only one record

Source: Internet
Author: User

Prerequisites:The same data is repeatedly written to the database, resulting in duplicate data with only the primary key ID, which now needs to be de-duplicated, preserving only one of the largest IDs in duplicate data Ideas:1. Find the record with duplicate data, and take the largest ID value 2 in the duplicate data, delete the record that does not contain the maximum ID value in the record implementation:DELETE from [Log_iis]. [dbo] . [iislog_table] WHERE ID not in(Select MAX(Id) from [iislog_table] Group  by [RequestTime] ,[LogFileName] ,[Logrow] ,[Date] ,[TIME] ,[cIp] ,[csusername] ,[ssitename] ,[scomputername] ,[sIp] ,[SPort] ,[Csmethod] ,[Csuristem] ,[csuriquery] ,[scstatus] ,[scsubstatus] ,[scwin32status] ,[scbytes] ,[csbytes] ,[Timetaken] ,[csversion] ,[cshost] ,[csuseragent] ,[Cscookie] ,[csreferer] ,[sevent] ,[Sprocesstype] ,[susertime] ,[skerneltime] ,[spagefaults] ,[Stotalprocs] ,[Sactiveprocs] ,[Sstoppedprocs] having Count(*) > 1)



From for notes (Wiz)



Sqlserver_ Delete duplicate rows keep only one record

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.