Facebook FQL Query OR
-
22-06-2021 - |
Domanda
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.
Soluzione
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 != ''
Altri suggerimenti
The answer provided by complex857 is correct but I would like to add some information. To make this query work you must add a LIMIT / OFFSET clause to your query.
SELECT post_id FROM stream
WHERE
(post_id IN (SELECT post_id FROM stream WHERE source_id = uid0 AND actor_id = uid1 LIMIT 1000 OFFSET 0)
OR
post_id IN (SELECT post_id FROM stream WHERE source_id = uid1 AND actor_id = uid0 LIMIT 1000 OFFSET 0))
AND message != '';
Hope this will help :)