Reputation: 11325
I'm trying to remove duplicates from a MySQL table where two column values will be the same.
In this case, I want to, say, have an id column (called nid), and a hash column with the same values:
| nid | hash |
| 2 | 932298 |
| 2 | 932298 |
I'd like only one of them to survive, preferably the first one inserted in the database.
I'm looking at this post but my use case is slightly different:
MySQL remove duplicates from big database quick
I'm also open to other options
Upvotes: 0
Views: 114
Reputation: 1180
simplest way of achieving it I believe:
1) create table `table_copy`(id int primary key,hash varchar(255), unique(`hash`)) select distinct id,hash from `table_name`;
2) drop table `table_name`;
3) rename table `table_copy` to `table_name`;
Upvotes: 0