`connections` stores undirected links; the same link may appear in both directions or twice, and bad rows may link a user to themselves (ignore those). For every user, suggest the non-connected users (not themselves) with whom they share the MOST mutual connections, considering only candidates with at least 2 mutuals. If several candidates tie for the most, return all of them. Return `user_id`, `suggested_id`, `mutual_count`. Order by `user_id`, `suggested_id`.
| Column | Type |
|---|---|
| user_a | INTEGER |
| user_b | INTEGER |
| user_a | user_b |
|---|---|
| 1 | 2 |
| 1 | 3 |
| 2 | 4 |
| 3 | 4 |
| 2 | 5 |
| 3 | 5 |
| 4 | 6 |
| 5 | 6 |
| user_id | suggested_id | mutual_count |
|---|---|---|
| 1 | 4 | 2 |
| 1 | 5 | 2 |
| 2 | 3 | 3 |
| 3 | 2 | 3 |
| 4 | 5 | 3 |
| 5 | 4 | 3 |
| 6 | 2 | 2 |
| 6 | 3 | 2 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Org Chart Span of Control · Listening Streaks of 3+ Days ›
{{ totalCount }} questions in the style asked at Amazon, Microsoft, Google, Meta, Flipkart and more — {{ hardPct }}% Hard. Write SQL in a real database engine in your browser, run it on sample data, then evaluate against hidden tests.
Company tags show where this type of question is commonly reported in interviews. Questions, data and solutions are written by TechTown.
{{ cur.statement }}
No submissions yet. Press Evaluate to submit your query.
{{ solutionSql }}
{{ out.error }}
You have solved your 3 free questions — nice work! Log in (free) to unlock all 150 questions, keep your streak and appear on the leaderboard.