I have two tables inside a database. One stores unique userNames and a unique id and the other stores which users from the previous table are “friends”: ex:
table users:
id | username
---------------
100 | aaa
200 | bbb
300 | ccc
table friends:
id | user | friend
-------------------
1 | 100 | 200
2 | 300 | 100
3 | 300 | 200
Like in the above example, user 100 is friends with 300 and also 200.
I’d like to display a list containing all of users 100 friends. Keep in mind he can appear in the “friends” table on both columns (user and friend). Can’t figure out how the query should look like. Everything i try, it duplicates rows and whatnot.
I know it’s trivial, but i’m new at this.
This will work with no duplicate