FQL is a SQL-style query provided by Facebook, FQL can query the data exposed by Facebook's graph API. Access https://api.facebook.com/method/fql.query?query=QUERY
, replacing the query part with any XML or JSON-formatted queries parameter.
SELECT [fields] FROM [table] WHERE [conditions]
FQL is different from SQL, and FROM
can only query a single table. You can also IN
SELECT
include subqueries in or with keywords WHERE
. However, a subquery cannot reference a variable in an external query. The properties that can be queried are only those items in the document that can be retrieved.
FQL can perform mathematical operations, base Boolean calculations, AND
or NOT
logical operations, as well as ORDER BY
LIMIT
clauses.
Any query needs to commit one uid
that you can call me()
. For example:
SELECT name FROM user WHERE uid = me()
Besides me()
, there are other available now()
, strlen()
, substr()
and strpos()
. Also rand()
available in ORDER BY
(for example ORDER BY rand()
).
The following statement shows how to query the current user and the current user's friend's personal information:
SELECT uid, name, pic_square FROM user WHERE uid = me() OR uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
The following example shows how to use the NOT
operation FQL to query the UID of a person who has participated in an event and is not the current user or a friend of the current user:
SELECT uid, name FROM user WHERE uid IN ( SELECT uid FROM event_member WHERE eid=209798352393506)AND NOT (uid=me())AND NOT (uid IN ( SELECT uid1 FROM friend WHERE uid2=me()))
FAQ:
How to get 10 random friends?
You can use ORDER by rand ().
select uid2 from friend where uid1 = me() order by rand() limit 10
Fql--facebook User Information Query interface