UNION
to create a symmetric friendship table that includes both (user1_id, user2_id)
and (user2_id, user1_id)
pairs.LEFT JOIN
between the symmetric friendship table and the Likes
table to find all pages liked by friends of each user.LEFT JOIN
to exclude pages that the user has already liked.user_id
and page_id
.user_id
, page_id
, and the count as friends_likes
for the final output.erDiagram Friendship { int user1_id int user2_id } Likes { int user_id int page_id } Friendship ||--o{ Likes : likes