The Page Recommendations SQL problem asks you to recommend pages to a user that their friends like but they haven't liked themselves. This requires finding the user's friends, collecting pages they liked, and filtering out pages already liked by the target user. The database interview pattern requires multi-table joins with NOT EXISTS or NOT IN filtering.
Meta asks this SQL problem because it models a core feature of social media — friend-based content recommendations. It tests JOIN for friend relationships, another JOIN for liked pages, and NOT EXISTS/NOT IN to exclude already-liked pages. This is a real-world SQL analytics scenario.
Friend JOIN + liked pages + exclusion filter. Find user1's friends via the Friendship table (bidirectional — check both user1_id = target and user2_id = target). Join friends with the Likes table to get liked pages. Exclude pages already liked by target user using NOT IN or LEFT JOIN + IS NULL.
SELECT DISTINCT l.page_id AS recommended_page
FROM Friendship f
JOIN Likes l ON (CASE WHEN f.user1_id = 1 THEN f.user2_id ELSE f.user1_id END) = l.user_id
WHERE (f.user1_id = 1 OR f.user2_id = 1)
AND l.page_id NOT IN (SELECT page_id FROM Likes WHERE user_id = 1)
Social network recommendation SQL follows a consistent pattern: find connections → collect attributes of connections → filter out already-seen attributes. The bidirectional friendship check (user1_id=target OR user2_id=target with corresponding partner column) is the most common source of bugs. Practice this pattern for "second-degree connections," "mutual friends," and "friend-of-friend recommendations."
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Apples & Oranges | Medium | Solve | |
| Customers Who Bought Products A and B but Not C | Medium | Solve | |
| Get Highest Answer Rate Question | Medium | Solve | |
| Project Employees III | Medium | Solve | |
| Reported Posts II | Medium | Solve |