How to bring potential friends(sql query) ?

Need to display all users with common friends.
for the current user (let it be id-ω 1) friends are chosen:
table structure:
to_id, from_id
1 2
5 1
3 2
3 5
//here the user id c-1 potential friends 1 is the user with id 3 Ohm
select if(to_id = 1 , from_id, to_id) friend_id from friends_table f1 where f1.to_id = 1 or f1.from_id = 1
September 26th 19 at 11:26
2 answers
September 26th 19 at 11:28
Not sure, maybe this:
SELECT *
FROM friends f
 INNER JOIN friends f1 ON f1.from_id = f.to_id
 INNER JOIN friends f2 ON f2.to_id = f.from_id
WHERE f.from_id = 1
 OR f.to_id = 1

Then from the result (and rows and columns) to remove the duplicate id.
September 26th 19 at 11:30
SELECT to_id FROM friends_table WHERE to_id IN (SELECT from_id FROM friends_table WHERE to_id = 1);

Find more questions by tags MySQLSQL