I am trying to get the body and the sender of all unread inbox .
To get all conversation's threads with unread messages I used this query:
SELECT thread_id from unified_thread WHERE folder='inbox' AND unread=1
to get the unread message of a thread I used this query
SELECT sender,body FROM unified_message WHERE unread=1
I have tried the following nested query :
SELECT sender,body FROM unified_message WHERE thread_id IN (SELECT thread_id FROM unified_thread WHERE folder = 'inbox' AND unread=1) AND unread=1"
but I only get unread message from one thread and not all unread threads.
I also tried multiquery like this:
String query1="SELECT thread_id FROM unified_thread WHERE folder='inbox' AND unread=1";
String query2="SELECT timestamp,sender,body FROM unified_message WHERE unread=1 AND thread_id IN (SELECT thread_id FROM #query1)";
Bundle params = new Bundle();
JSONObject jsonFQL=new JSONObject();
try {
jsonFQL.put("query1",query1);
jsonFQL.put("query2",query2);
} catch (JSONException e) {
e.printStackTrace();
}
params.putString("method","fql.multiquery");
params.putString("queries", jsonFQL.toString());
new Request(session,"/fql",params,HttpMethod.GET,new Request.Callback(){
public void onCompleted(Response response) {
...
}
).executeAsync(); ....
but I got error:
errorMessage: Unsupported method, fql.multiquery
Then I tried with INNER JOIN:
SELECT unified_message.sender,unified_message.body
FROM unified_message
INNER JOIN unified_thread
ON unified_message.thread_id=unified_thread.thread_id
WHERE unified_thread.unread=1
but I got this error:
Parser error: unexpected 'INNER' at position...
I learnt JOIN is not supported in FQL
Can somebody give me a hand to do this query in FQL ??
example of needed output: I have 5 conversations with different people, but only 3 conversations have unread messages. So I would like to get something like this:
UNREAD MESSAGES
Sender: Anna
Body: hello dude
Body: how are you?
Body: I miss you
Sender: John
Body: please help me
Sender: Erick
Body: nice
Body: buddy
This works:
SELECT sender, body FROM unified_message
WHERE thread_id IN
(SELECT thread_id FROM unified_thread WHERE folder = 'inbox' AND unread=1)
AND unread=1
ORDER BY timestamp DESC
It is important to sort the messages you retrieve in a descending order using:
ORDER BY timestamp DESC
Otherwise, only the first older messages of the conversation will be examined, whereas unread messages should be recent.
Just for your knowledge, here is the corresponding multi-query, which gives the same result:
{
"threads":"SELECT thread_id FROM unified_thread WHERE folder='inbox' AND unread=1",
"messages":"SELECT sender, body FROM unified_message WHERE thread_id IN (SELECT thread_id FROM #threads) AND unread=1 ORDER BY timestamp DESC"
}
However, you should not use FQL anymore:
Version 2.0 of the Facebook Platform API is the last version where FQL will be available. Versions after 2.0 will not support FQL. Please migrate your applications to use Graph API instead of FQL. Please see our changelog for current version information.
I suggest you use the following Graph API tables:
By the way, FQL doesn't have such INNER JOIN
.