Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to delete one of two duplicates with SQL statement

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report