SQL Server deletes duplicate records

Source: Internet
Author: User

In the system to a customer on-line found that there is a table of duplicate data, the results by troubleshooting code to find that there is a problem with the business logic, after modifying the code needs to be in the database of data deduplication on CSDN to find a solution, do not delete the database on the wire as much as possible, and you should back up the database regardless of any action on the database on the line
  
 
  1. --删除重复的记录
  2. delete from table1
  3. --根据Uid号获取重复的记录
  4. where uid in (select uid from table1 group by uid having count(uid) > 1)
  5. --排除保留最新的ID号,其他的删除
  6. and id not in (select max(id) from table1 group by uid having count(uid )>1)

Reference: CSDN SQL Duplicate record query

From for notes (Wiz)

SQL Server deletes duplicate records

Related Article

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.