I would like to store friendships in a database. My idea is that when user1 becomes friends with user2 I store that friendship so that I can get all of either user's friends if I ever need it. At first I thought I would just store their id's in a table with one insert, but then I thought about some complications while querying the db.
If I have 2 users that have a user id of 10 and 20 should I make two inserts into the db when they become friends
ID USER1 USER2
1 10 20
2 20 10
or is there a way to query the db to only get a particular users friends if I only did one insert like so
ID USER1 USER2
1 10 20
I know the first way can definitely 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 way can be queried to get me the result I would be looking for like all of user 10's friends.