Search code examples
facebookfacebook-fqlfql.multiquery

Facebook FQL Query OR


I am trying to create an OR clause in FQL query.

Here is my query :

SELECT post_id, message, permalink, likes, actor_id, created_time FROM stream  WHERE 
(source_id = xxx1 AND message != '' AND actor_id = xxx2) 
OR 
(source_id = xxx2 AND actor_id = xxx1) 

Globally I want to retrieve all the messages between 2 Facebook users. If I remove the OR clause I do receive messages in one way but adding the OR removes every messages I have as if the '(' do not work.

If you need to test this query please go on : http://developers.facebook.com/tools/explorer and create and access token with the read_stream permission (Extended Permissions)

I also wanted to use a UNION but it is not supported by FQL. Maybe I could use FQL multiple queries but I was still blocked by the UNION missing.

Thank you for your help.


Solution

  • You can use sub queries to achieve the desired result like this:

    SELECT post_id, message FROM stream 
    WHERE 
        (
          post_id in (select post_id from stream where actor_id = uid0 and source_id  = uid1) 
        or  
          post_id in (select post_id from stream where actor_id = uid1 and source_id  = uid0)
        ) 
        and message != ''