Showing posts with label mysql sql tips duplicates. Show all posts
Showing posts with label mysql sql tips duplicates. Show all posts

Wednesday, August 18, 2010

How to remove duplicates from table (MySQL)

table_users(
id INT PRIMARY KEY,
username TEXT
);

delete from table_users
USING table_users, table_users as vtable
WHERE (table_users.id > vtable.id)
AND (table_users.username=vtable.username)

(table_users.id > vtable.id) - should return only one row