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 a User’s Listings by Category

Problem

I need to retrieve all of a specified user’s listings that are in a specific category.

Solution

SELECT title,listing_id, description, category FROM listing WHERE
 category = $category AND poster = $user;

Discussion

Unfortunately, there’s no way to retrieve all of the listings in a category independently of the poster, as you ultimately need a WHERE clause that acts on either the poster or listing_id fields.

You can easily modify this recipe to search for all of the listings in a category from all of the user’s friends:

SELECT title, url, description, price category FROM listing
 WHERE category = $category AND poster IN (SELECT uid2 FROM friend
 WHERE uid1 = $user);

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