1

i have a table for friendship

CREATE TABLE IF NOT EXISTS `friendList` (
  `id` int(10) NOT NULL,
  `id_friend` int(10) NOT NULL,
  KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

I have some entries like :

Entry A : 1-2

Entry B : 2-1

Entry C : 1-2

Entry A & B show that the user 1 is friend with user 2. But the entry C is useless, so i need to delete it.

Is there way i can delete all duplicate row or apply specific constraint to avoid that?

Thanks !

  • what is your table structure> – sumit Dec 13 '13 at 04:50
  • refer to this link http://stackoverflow.com/questions/4685173/delete-all-duplicate-rows-except-for-one-in-mysql – user2936213 Dec 13 '13 at 04:51
  • The thing is that the id key is not unique and is not meant to be. I was looking for another solution than adding a unique primary key, but may be its just impossible. Thanks for your answer anyway. – user3093547 Dec 13 '13 at 04:54

1 Answers1

0

You can add a unique index for those 2 columns to enforce uniqueness:

alter table friendList add unique index(id, id_friend);
Szymon
  • 42,577
  • 16
  • 96
  • 114