I am trying to design a very simple table that stores the data of friends in a community.
Therefor I store the userId
of 2 friends respectively.
Goal
User wants to load his/her friends list.
t_friends Option 1:
Query
SELECT * FROM t_friend WHRE user_id = 10
10
is the current userId
of the user which is looking for his friends list and he has 1 friend userId(20)
This way userId (10)
finds his friend (20)
BUT what if userId(20)
were looking for his friends?
The query is coupled with userId
.
That leads me to another design that contains redundant data:
t_friends option 2:
userId (10)
loads now:
SELECT * FROM t_friend WHRE user_id=10
Similiar to that the query for userId(20)
would then be:
SELECT * FROM t_friend WHRE user_id=20
But what about the redundancy? That leads me then to that query using table design option 1:
SELECT * FROM t_friend WHERE user_id=10 OR friend_id=10
I have a feeling that there is a smarter way to solve that. Do You have any experiences with that structure?
Thanks