Magicsheet logo

Page Recommendations

Medium
25%
Updated 8/1/2025

Asked by 1 Company

Topics

Page Recommendations

What is this problem about?

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.

Why is this asked in interviews?

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.

Algorithmic pattern used

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)

Common mistakes candidates make

  • Not handling bidirectional friendship (both columns must be checked).
  • Not using DISTINCT on page_id (multiple friends can like the same page).
  • Including pages already liked by the target user.
  • INNER JOIN instead of the filtered approach losing some friendships.

Interview preparation tip

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."

Similar Questions