FQL results can be sorted before they're returned, by making use of the ORDER BY
query, just like you would do in a SQL request. Results can be sorted alphanumerically ascending or descending, and both normal data fields and advanced data fields can be used in the sort process.
In this recipe we're going to create an FQL request for the current user's friends, which will also apply a sort to the data prior to returning it to our application.
Our starting FQL request should look like this:
SELECT uid,name
FROM user
WHERE uid
IN (
SELECT uid2
FROM friend
WHERE uid1 = me()
)
To apply sorting to the results of our request, we need to add the ORDER BY
statement to our requests, specifying one of the table's columns as the target, and whether the sort should be ascending (ASC) or descending (DESC).
To retrieve the list of the current user's friends, and then sort the results based on the name of the user, we would use the following FQL query:
SELECT...