I would like to keep friendships in a database. My idea is that when user1 becomes friends with user2, I keep this friendship so that I can get all of the user's friends if I ever need it. At first, I thought that I would just keep my identifier in a table with one insert, but then I thought about some of the complications when querying db.
If I have 2 users that have user IDs 10 and 20, I have to do two inserts in db when they become friends
ID USER1 USER2 1 10 20 2 20 10
or is there a way to request db to get only specific user friends if I only inserted them like this
ID USER1 USER2 1 10 20
I know that the first way can give me what I am looking for, but I would like to know if this is good practice and if there is a better alternative. And if the second method can be requested to get the result, I would search, like all users, 10 friends.
source share