I have a table with only a primary key column and a text column. The text column has duplicate values and I want those gone.
What have I tried
I googled around a bit and quickly found what I thought was the answer, which was this:
ALTER IGNORE TABLE tablename ADD UNIQUE INDEX index_name (column1);
But after trying to execute the query I ended up with MySQL saying: "#1062 - Duplicate entry 'v&d' for key 'remove_duplicates'". So after fiddeling with that for a while I found that it didn't work.
After that I tried creating a tmp table and removing the old one, but I couldn't get that going either. I may have gotten the syntax wrong which was:
CREATE table `tmp` like `Tag`
alter table tmp add unique (text)
INSERT IGNORE INTO `tmp` SELECT * FROM `Tag`
RENAME TABLE `Tag` TO `deleteme`
RENAME TABLE `tmp` TO `Tag`
DROP TABLE `deleteme`;
What do I want
A table that has no duplicate values for column 'text'. If anyone sees any errors with my previous methods please let me know, or if you think it should/could be done in a different way please let me know!
Edit
I forgot to mention that I also have a relation hanging on the PK (yeah, quite important I know). Is there some way to "preserve" the relation with the other table as well? I could manually change the id's in the other table if need be, but a way to change that as well would be great.