Friend Recommendations by Mutual Friend Count
Problem
**[Asked at Meta]**
For user `1`, find all **friend-of-friend candidates** (users connected through
a mutual friend, but not directly friends with user 1) and rank them by mutual
friend count.
Return `recommended` (user_id) and `mutual_count`, ordered by mutual_count
descending then user_id ascending.
Tables
Example rows — the live problem includes the full dataset.
friendships
| user_id | friend_id |
|---|
Expected output
Your answer should return 2 rows with the columns recommended, mutual_count.
Starter code (SQL)
SELECT *
FROM friendships;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock