Get the App
SLTechnology News&Howtos  ›  Database  › 

How to delete one of two duplicates with SQL statement

Shulou Source: shulou.com Published: 2022-05-31 18:14:36 10月05日 Update

This article introduces the knowledge of "how to delete one of the two duplicate data with SQL sentence". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The code for copying any test table is as follows: CREATE TABLE test_delete (name varchar (10), value INT) Go-Zhang San 100 and Wang Wu 80 are INSERT INTO test_delete SELECT 'Zhang San', 100 UNION ALL SELECT 'Zhang San', 100 UNION ALL SELECT'Li Si', 80 UNION ALL SELECT 'Wang Wu', 80 UNION ALL SELECT 'Wang Wu', 80 UNION ALL SELECT 'Zhao Liu', 90 UNION ALL SELECT 'Zhao Liu', 70 go-Test search data SELECT ROW_NUMBER () OVER (PARTITION BY name, value ORDER BY (SELECT 1)) AS no, name, value FROM test_delete

No name value-1 Li Si 80 1 Wang Wu 80 2 Wang Wu 80 1 Zhang San 100 2 Zhang San 100 1 Zhao Liu 70 1 Zhao Liu 90-the copy code for creating a view is as follows: CREATE VIEW tmp_view AS SELECT ROW_NUMBER () OVER (PARTITION BY name, value ORDER BY (SELECT 1)) AS no, name, value FROM test_delete

-- Delete data 1 > DELETE FROM tmp_view WHERE no! = 12 > go (2 rows affected)-- check result 1 > www.xuebuyuan.com 2 > select * from test_delete; 3 > go name value-- Zhang San 100 Li Si 80 Wang Wu 80 Zhao Liu 90 Zhao Liu 70 (5 rows affected) author tearsmo

This is the end of the content of "how to delete one of the two duplicate data with the SQL statement". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Zhang San Wang Wu data code Li Si sentences content more knowledge influence testing practicality success in learning and then author dilemma actual situation articles cases Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Docker NVidia Shulou Information Shulou Technology