Alex Rivera | Logout

how to represent symmetric many to many relationship

Asked 2010-08-23T17:31:58.590
10

suppose i have a entity called USER and a relationship FRIENDSHIP exist between two USERs SO for that i have a table 'USER' and a relationship table 'FRIENDSHIP'

   

USER id firstName LastName 1 taher chhabrawala 2 john Dsouza 3 rahul singh 4 deepak patel

Friendship id id 1 2 1 3 1 4 4 1 4 3

In the above table i am storing the same information twice i.e "taher is a friend of deepak and deepak is a friend of taher"

Is there any way to reduce this redundancy ?

Edit
Report

1 Answer

5

Make up a rule like 'the first ID value is always lower than the second ID value,' so you can ensure there are no duplicates.

In that case, pair (4,1) is invalid, and pair (4,3) would be stored as (3,4).

answered 2010-08-23T17:58:02.177

Your Answer