Use the DISTINCT keyword in FQL - facebook

I am trying to find the distinct user IDs on comments to a post. I know this can be done with SQL with the DISTINCT clause, but I am not sure how it might be done with fql. If there is not any way, what would be one approach to doing so, assuming I pull down all the fromid on a post_id?

FQL isn't like SQL in the sense that you don't get duplicates for the same reasons SQL does (JOINs, etc.), so no, there's no DISTINCT keyword that I know of. If you're having an issue parsing a specific query, you should post that so we can help further.

Related

FQL: Get comment data WHERE object_id={a known object_id} works, but WHERE id={a known comment XID} does not?

I'm using FQL to get comment data from webpage with a Facebook comment box. I use the graph to get the object_id, then use FQL to get all comments with that object_id. However, if I want to pull data from a specific comment using its id (sometimes referred to as an XID) the FQL returns 0 results.
According to https://developers.facebook.com/docs/reference/fql/comment/ the id should be indexed, so this query should work:
SELECT+id,+text,+time,+fromid,+is_private+FROM+comment+WHERE+id={some known XID}
But it doesn't. BTW, THIS query does work:
SELECT+id,+text,+time,+fromid,+is_private+FROM+comment+WHERE+object_id={some known object_id}
It is irritating how I can't pull query for comments using time or fromid or anything other than object_id, id, post_id, and parent_id... but in practice only using the object_id returns anything.
has anyone else run into this problem? Is my XID query wrong somehow, or is the id only indexed on certain kinds of comments, and not webpage comments for no inexplicable reason?
This one I managed to solve with trial and error. I had to put the id in single quotes. It's odd, I could query the object_id without putting it in quotes, but not the id. This is sort of what the working FQL looked like, except with a valid access token:
SELECT+id,+text,+time,+fromid,+is_private+FROM+comment+WHERE+id='#########_####'
as opposed to:
SELECT+id,+text,+time,+fromid,+is_private+FROM+comment+WHERE+id=#########_####
which failed to return any results.
Thanks for being consistent, Facebook :(

Does Group by with order by work ion Dql?

I am trying to execute a DQL (Doctrine) query that retrieve the latest answers of different doctors.
we have table answer, member, Location (doctor table) and many other table connected to the doctor information. However I want to get the latest answer but the condition is one answer for a doctor. I do some search and know something about group by and order by dont work together !
Here is the query in DQL:
$query = Doctrine_Query::create()
->select("a.answer_id as answer_id,m.member_is as member_id,a.member_id")
->from('Answer a')
->leftJoin('a.Member m on m.member_id = a.member_id')
->orderBy('a.date_added DESC')
->groupBy('m.member_id')
->limit(5);
but this query return undesirable results. Can anyone tell me where is the mistake?
Unfortunately you need to perform a subquery for that, which according to this question, DQL does not support. However in that question it's suggested that you send a native query.

"show tables" or "describe" in FQL?

I was curious to know if there is a way to problematically get s list of all the FQL tables, a list of all their columns and which columns are index-able. I can't find anything in the documentation short of following the docs to create data objects defining these details for each FQL table.
Well, I haven't tried myself, but this seems to do exactly what you've asked for.
https://github.com/jwerle/fql-workbench/blob/master/README.md
I think it doesn't exists, however, Facebook has a complete reference about available tables, with all their respective columns and column data types:
https://developers.facebook.com/docs/reference/fql/
Regards.
It is possible to implement a show-tables or describe functionality in FQL using the tables 'column' and 'table'. This is what https://developers.facebook.com/docs/reference/fql/ says about it:
column - An FQL table that documents columns in other FQL tables
table - An FQL table containing information about other FQL tables
We can query these tables using FQL to find out the schema of the regular tables.

Facebook IN clause in FQL query

I have a big problem with Facebook FQL, if i do
select message from stream where source_id=175102475936031
I can get the correct data, if i do this
select message from stream where source_id IN(175102475936031,etc,etc,etc)
I got a empty JSON, why? is there any alternative to this select? I have to read the messages from multiple events.
Is your problem solved?
"IN" query is a supported feature of FQL. I have tried it multiple times.
Only needs to have:
column indexable
needs to have permission to access data
data should be present for at least one column :P
select message from stream where source_id IN( 175102475936031, etc, etc, etc)
"NOT IN" is not a supported feature of FQL. Ref: http://forum.developers.facebook.net/viewtopic.php?id=1420

Facebook - max number of parameters in “IN” clause?

In Facebook query language(FQL), you can specify an IN clause, like:
SELECT uid1, uid2 FROM friend WHERE uid1 IN (1000, 1001, 1002)
Does anyone know what's the maximum number of parameters you can pass into IN?
I think the maximum result set size is 5000
It may seem like an odd number (so perhaps I miss counted, but it's close ~1), but I can not seem to query more than 73 IN items. This is my query:
SELECT object_id, metric, value
FROM insights
WHERE object_id IN ( ~73 PAGE IDS HERE~ )
AND metric='page_fans'
AND end_time=end_time_date('2011-06-04')
AND period=period('lifetime')
This is using the JavaSCript FB.api() call.
Not sure if there is an undocumented limit or it might be an issue of facebook fql server timeout.
You should check if there is a error 500 returned from FB web server which might indicate you are passing a too long GET statement (see Facebook query language - long query)
I realized my get was too long so instead of putting many numbers in the IN statement, i put a sub-query there that fetches those numbers from FB FQL - but unfortunately it looks like FB couldn't handle the query and returned an 'unknown error' in the JSON which really doesn't help us understand the problem.
There shoud not be a maximum number of parameters as there isnt in SQL IN as far as I know.
http://www.sql-tutorial.net/SQL-IN.asp
just dont use more parameters than you have values for the function to check because you will not get any results (dont know if it will give away an error as I never tried to).