0

Possible Duplicate:
Remove duplicate rows in MySQL

I have the following query that shows duplicate rows:

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

I've only been able to find queries that remove both of them instead of just removing one of them (say the one with the highest ID).

Any ideas?

Community
  • 1
  • 1
Motive
  • 3,001
  • 9
  • 39
  • 63

2 Answers2

1

Please try this sql to delete duplicate rows:

delete from users where id not in (select min(id) from users group by user_email)
udalmik
  • 7,547
  • 25
  • 40
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
                       );

I guess this will work

ClearLogic
  • 3,436
  • 1
  • 21
  • 31
Naga
  • 752
  • 2
  • 7
  • 12