Detailed example of removing duplicate data in MySQL There are two meanings of duplicate records: one is a completely duplicate record, that is, all fields are repeated; the other is a record with some fields repeated. The first type of duplication is relatively easy to solve. You only need to use the distinct keyword in the query statement to remove duplicates. Almost all database systems support the distinct operation. The main reason for this duplication is poor table design, which can be avoided by adding a primary key or unique index column to the table. select distinct * from t; For the second type of duplicate problem, it is usually required to query any one of the duplicate records. Assume that table t has three fields: id, name, and address. id is the primary key. The repeated fields are name and address. It is required to get a unique result set for these two fields. -- Oracle, MySQL, using correlated subqueries select * from t t1 where t1.id = (select min(t2.id) from t t2 where t1.name = t2.name and t1.address = t2.address); -- Hive only supports subqueries in the FROM clause. Subqueries must have names and columns must be unique. select t1.* from t t1, (select name, address, min(id) id from t group by name, address) t2 where t1.id = t2.id; -- You can also use hive's row_number() analysis function select t.id, t.name, t.address from (select id, name, address, row_number() over (distribute by name, address sort by id) as rn from t) t where t.rn=1; Thank you for reading, I hope it can help you, thank you for your support of this site! You may also be interested in:
|
<<: Sample code for implementing login and registration template in Vue
>>: Detailed steps for quick installation of openshift
ins and del were introduced in HTML 4.0 to help au...
Preface: I received crazy slow query and request ...
Table of contents Preface know Practice makes per...
Redis is an open source NoSQL database written in...
Preface: Use debugbar to view document code in iet...
Preface If CSS is the basic skill of front-end de...
This article describes how to use docker to deplo...
RGBA is a CSS color that can set color value and ...
remember: IDE disk: the first disk is hda, the se...
Hello everyone, today I want to share with you ho...
1. First prepare the MySQL and Eclipse environmen...
Recently, I participated in the development of th...
First of all, let me talk to you about my daily l...
If we want to perform batch operations on a type ...
After the docker installation is completed on the...