0

MySQL 怎样查看重复数据并且删除重复行数据?

odelette created at5 years ago view count: 2280

有一些重复的数据,想把重复的数据给删掉,有没有SQL直接一次删除?

report
回复
0

比如users里面查看name重复的数据,用下面的SQL就行

SELECT 
  a.*, 
  b.* 
FROM 
  users AS a, 
  users AS b 
WHERE 
  (
    a.`name` = b.name 
    OR a.name IS NULL 
    AND b.name IS NULL
  ) 
  AND a.ID < b.ID;

删除使用

DELETE a
FROM users as a, users as b
WHERE
          (a.`name`   = b.name OR a.name IS NULL AND b.name IS NULL)
        AND a.ID < b.ID;
5 years ago 回复

相关搜索关键词

Recent search keywords