Must use FQL Multiquery to retrieve data
Posted by mahmud ahsan on October 25, 2009
FB Connect, Facebook
If you are developing facebook application or facebook connect base application, then you might know how to retrieve data from FQL tables.
To retrieve data from FQL tables facebook provides two api methods, fql_query() and fql_multiquery()
Using both functions, you can evaluate fql queries, but if you need to evaluate a series of queries then remember, you should use fql_multiquery()
syntax and usage of fql_multiquery:
$query1 = "SELECT uid, name from user where uid in ($friends)";
$query2 = "SELECT pid, subject, text from photo_tag where pid in ($pids)";
$queries = '{
"query1": "' . $query1 . '",
"query2": "' . $query2 . '"
}';
$result = $facebook->api_client->fql_multiquery($queries);
$userInfo = $result[0]['fql_result_set'];
$photoTags = $result[1]['fql_result_set'];
Advantage of using fql_multiquery:
- Multiple queries in one call
- Fetch data from one query and use it in another query within the same call
- Better performance than running a series of fql.query calls with batch.run.
For point 2, think you may want to get some data about users who are attending an event. Then at first you have to retrieve uids for that event and then using another fql call you have to retrieve user data. Now here you’ll see how you can integrate this solution using fql_multiquery()
$query1 = "SELECT uid, rsvp_status FROM event_member WHERE eid=$eventId";
$query2 = "SELECT name, url, pic FROM profile WHERE id IN (SELECT uid FROM #query1)";
$queries = '{
"query1": "' . $query1 . '",
"query2": "' . $query2 . '"
}';
$result = $facebook->api_client->fql_multiquery($queries);
Look in query2, you are referencing the result of query1 by #query1
To learn more about FQL and FQL Queries visit:
- http://wiki.developers.facebook.com/index.php/FQL
- http://wiki.developers.facebook.com/index.php/Fql.multiquery
- http://wiki.developers.facebook.com/index.php/Fql.query
Random Posts
Comments (3)







Hi. Very interesting Post. Not really what i have searched over Google, but thanks for the information.
Hello there. Thank you. I check it regularly to get the newest stuff.
What about the major disadvantage: If one query fails, both will fail. So you cant do individual exception handling for each query with this method.
So I suggest, we use it only for complex queries as in example 2, and not just to save connection calls.