Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete duplicated mysql rows with no primary key

Tags:

mysql

Hi i have a mysql table without primary key and i need to delete the duplicated rows. how can i do so?

user_id category_id
1            2
1            3
1            4
1            2
2            2
2            3
2            2
like image 454
Damian Sia Avatar asked Nov 16 '11 05:11

Damian Sia


1 Answers

 CREATE TABLE temp SELECT DISTINCT * FROM tablename;
 ALTER TABLE tablename RENAME junk;
 ALTER TABLE temp RENAME tablename;
like image 187
Adrian Cornish Avatar answered Nov 15 '22 18:11

Adrian Cornish