码迷,mamicode.com
首页 > 其他好文 > 详细

删除重复数据,不保留

时间:2020-03-29 19:52:37      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:src   数据   arc   drop   val   select   dynamic   ima   code   

-- 建表

DROP TABLE IF EXISTS `table1`;
CREATE TABLE `table1` (
`id` int(11) NULL DEFAULT NULL,
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;


INSERT INTO `table1` VALUES (2, ‘B‘);
INSERT INTO `table1` VALUES (3, ‘C‘);
INSERT INTO `table1` VALUES (4, ‘D‘);
INSERT INTO `table1` VALUES (5, ‘E‘);
INSERT INTO `table1` VALUES (1, ‘A‘);
INSERT INTO `table1` VALUES (1, ‘A‘);

-- 查询

技术图片

 

 --删除,结果

delete from table1 where name in (
SELECT * from (
SELECT name from table1 GROUP BY name having COUNT(id)>1)a
)

技术图片

 

删除重复数据,不保留

标签:src   数据   arc   drop   val   select   dynamic   ima   code   

原文地址:https://www.cnblogs.com/liyunchuan/p/12594146.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!