friendships is undirected: a pair may be stored as (a, b), as (b, a), or both; rows where user_a = user_b are bad data and must be ignored. Suggest pairs of users who are NOT friends but have at least 2 mutual friends. Return user_1 (smaller id), user_2 (larger id) and mutual_friends. Order by mutual_friends DESC, user_1, user_2.
| Column | Type |
|---|---|
| user_a | INTEGER |
| user_b | INTEGER |
| user_a | user_b |
|---|---|
| 1 | 2 |
| 1 | 3 |
| 2 | 4 |
| 3 | 4 |
| 4 | 5 |
| 1 | 5 |
| 2 | 3 |
| user_1 | user_2 | mutual_friends |
|---|---|---|
| 1 | 4 | 3 |
| 2 | 5 | 2 |
| 3 | 5 | 2 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Clicks per Domain From Raw URLs · As-Of Price Join for Trade Valuation ›
{{ 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.