Home > database >  Mysql delete duplicate data only keep one
Mysql delete duplicate data only keep one

Time:01-17

The CREATE TABLE ` knowledge_synonym ` (
` id ` INT (11), NOT NULL AUTO_INCREMENT,
` kbId ` INT (11) NOT NULL,
` word ` VARCHAR (255) CHARACTER
The SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
CHARACTER ` wordSynonym ` VARCHAR (10000)
The SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
` synonymNum ` INT (11) the DEFAULT NULL,
CHARACTER ` createTime ` VARCHAR (255)
The SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
CHARACTER ` updateTime ` VARCHAR (255)
The SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
PRIMARY KEY (` id `),
The KEY ` index_one ` (` kbId `)
) ENGINE=INNODB AUTO_INCREMENT=189 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;


Delete the word field repeat data, keep the id of the smallest a

The delete from knowledge_synonym where id not in
(
Select id from (
The select min (id) id from knowledge_synonym t group by t.w word
) z
)
  • Related