Retrieving Events Two Users Are Attending

Problem

I need to find all of the events that two users are attending, using FQL.

Solution

Assuming the current loggedinuser is friends with both of these users (or otherwise allowed to see their events):

SELECT name FROM event WHERE eid IN (SELECT eid FROM
 event_member WHERE uid = $user1 AND eid IN (SELECT eid FROM event_member
 WHERE uid= $user2))

You’ll need to plug the two IDs in as user1 and user2.

Discussion

This should be pretty easy to extend for more than two users if you need to, and it shouldn’t affect performance considerably, since the heavy lifting is done by the database.

Get Facebook Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.