Question

I have an FQL query that is returning the list of people who have commented on a post:-

SELECT time, fromid, likes, post_id_cursor from comment where post_id = '331288023558058_592220760798115' ORDER BY time DESC LIMIT 5000

What I'd like to do is to include another query within this query to return more details of the person leaving a comment

SELECT sex, first_name, middle_name, last_name, username, locale, profile_url, pic_square_with_logo FROM user WHERE uid = {fromid of person leaving comment}

Is it possible to combine the queries so that I get all the data in a single query? Any ideas how?

Thanks

Jonathan

Was it helpful?

Solution

use multiqueries

commentquery = "SELECT time, fromid, likes, post_id_cursor from comment where post_id = '331288023558058_592220760798115' ORDER BY time DESC LIMIT 5000"

userquery = SELECT sex, first_name, middle_name, last_name, username, locale, profile_url, pic_square_with_logo FROM user WHERE uid = (SELECT fromid FROM #commentquery)

To user multiple FQL queries, you need to json_encode the queries in an array. for the /fql?q= parameter

So to specify:

$queries = [];
$queries['comments'] = "SELECT time, fromid... ";
$queries['users'] = "SELECT sex, ... WHERE uid IN (SELECT fromid FROM #comments)";

$fql = json_encode($queries);
// then using curl or whatever 
// (multiqueries don't work with PHP sdk's $facebook->api() i believe)
GET http://graph.facebook.com/fql?q=$fql

OTHER TIPS

Use a multi-query

graph.facebook.com/fql?q={"query1":"SELECT time, fromid, likes, post_id_cursor from comment where post_id = '331288023558058_592220760798115' ORDER BY time DESC LIMIT 5000","query2":"SELECT sex, first_name, middle_name, last_name, username, locale, profile_url, pic_square_with_logo FROM user WHERE uid IN (SELECT fromid FROM #query1)"}

https://developers.facebook.com/docs/technical-guides/fql/

You can probably find your answer here: fql join; can i join two tables with FQL?

You want to join the two queries with a multiquery. Hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top