SQLQuokka
Start practicing
QuestionsLearnSandboxFeaturesRoadmapFAQ

People You May Know

Unsolved

Meta's 'People You May Know' feature suggests two users to each other when they are not yet friends but share at least 2 mutual friends. The `friendships` table stores each friendship once (as a single row, in either direction), and friendship is symmetric. Write an SQL query that returns each recommended pair once, as `user_id`, `recommended_user_id` (with `user_id` smaller than `recommended_user_id`) and `mutual_friends` (the number of friends they have in common). Order the results by `mutual_friends` descending, then `user_id` ascending, then `recommended_user_id` ascending.

SQL Query Editor (Ctrl+Enter to run)
0 characters · Valid
Canonical Solution Official

Official Solution is Hidden

Try solving the question with the schema explorer and hints first. When ready, reveal the verified canonical query and step-by-step logic breakdown.

Community Q&A & Discussion

Ask questions, share alternate queries, and explore solutions

0 comments
Asked By:
🏢 LinkedIn🏢 Meta🏢 Snap

Submission History

Your recent query executions and answer checks

Execution Pipeline:
FROM friendships
Full source dataset
11 rows total
Ready. Type a query to see live execution.
Clause: Auto-Sync · AlaSQL Engine