0

可能重复:
删除 MySQL 中的重复行

我有以下显示重复行的查询:

SELECT ID, user_login, wp_users.user_email FROM wp_users
INNER JOIN (SELECT wp_users.user_email FROM wp_users
GROUP BY wp_users.user_email HAVING count(ID) > 1) dup ON wp_users.user_email = dup.user_email

我只能找到同时删除它们的查询,而不仅仅是删除其中一个(比如 ID 最高的那个)。

有任何想法吗?

4

2 回答 2

1

请尝试使用此 sql 删除重复行:

delete from users where id not in (select min(id) from users group by user_email)
于 2012-09-11T21:12:46.660 回答
0
DELETE FROM 
table_name A
WHERE  a.rowid >  ANY ( SELECT B.rowid
                        FROM table_name B
                        WHERE A.col1 = B.col1 AND 
                              A.col2 = B.col2
                       );

我想这会奏效

于 2012-09-11T21:03:57.177 回答