Buddy List: Relational Database Table Design

Posted by huntaub on Stack Overflow See other posts from Stack Overflow or by huntaub
Published on 2010-06-17T01:11:11Z Indexed on 2010/06/17 1:42 UTC
Read the original article Hit count: 314

So, the modern concept of the buddy list:
Let's say we have a table called Person. Now, that Person needs to have many buddies (of which each buddy is also in the person class). The most obvious way to construct a relationship would be through a join table. i.e.

buddyID   person1_id   person2_id
0         1            2
1         3            6

But, when a user wants to see their buddy list, the program would have to check the column 'person1_id' and 'person2_id' to find all of their buddies.

Is this the appropriate way to implement this kind of table, or would it be better to add the record twice.. i.e.

buddyID   person1_id   person2_id
0         1            2
1         2            1

So that only one column has to be searched.

Thanks in advance.

© Stack Overflow or respective owner

Related posts about best-practices

Related posts about database-design