O'Reilly logo

Facebook Cookbook by Jay Goldman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Retrieving the 10 Most Recent Photos from a User

Problem

I need to retrieve the 10 most recently posted photos by a specific user using FQL.

Solution

SELECT pid, src, caption FROM photo WHERE aid IN (SELECT
 aid FROM album WHERE owner = $user) ORDER BY created DESC LIMIT 10;

Discussion

The owner field isn’t indexed in the photo table, so we need to make a subquery into the album table to find photos owned by a specific user.

The ORDER BY and LIMIT clauses can be applied to any of the queries in this chapter to order and/or constrain the result set.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required