I have one table in mysql named
'UserFriends' where I am updating my websites user's friends details.
here is the schema of the table (
id int, Userid int, friendid int, createdate timespan
now, I want to create unique index on
userid & friendid. that i have created unique index well. so, right now i am not able to insert same
friendid as duplicate. but if i am inserting same value in opposite field it accept without generating error.
insert into userfriends ( userid, friendid ) select 1, 2 --- insert perfect insert into userfriends ( userid, friendid ) select 1, 2 --- show error because unique index comes in a picture
now i am inserting
insert into userfriends ( userid, friendid ) select 2, 1 --- records insert here (i don't want this)
How do i prevent this?