RQL allows you to make queries on arbitrary Sociali data (assuming your application has access!). For more details see rql.query, the rql docs on the developer site, and rql Tables.

Some example rql queries

Get the uids of all friends of the $app_user who have the app installed:

SELECT uid FROM user WHERE has_added_app = 1 
AND uid IN (SELECT uid2 FROM friend WHERE uid1 = $app_user)  

Get the names of the groups u1 is a member of:

SELECT name FROM group WHERE gid IN (SELECT gid FROM group_member WHERE uid = u1)  

See groups' names that u1 shares with u2:

SELECT name FROM group  WHERE gid IN (SELECT gid FROM group_member WHERE uid=u1 
AND gid IN (SELECT gid  FROM group_member  WHERE uid=u2))  

In PHP would look like this: (making sure to include Sociali.php and lib)

$query = "YOUR QUERY HERE"; 
//(see above examples) $array=$Sociali->api_client->rql_query($query);  

The returned array is multidimensional, so an easy way to get at the data without the foreach loop
(*assuming you've only pulled one row, ie using "WHERE uid=$user"):

$attribute = $array[0]['attribute'];  

If there are no rows returned (ie. you look for photos of people together but no photos of them exist), the PHP Sociali client will return an empty string. You can check to see if there are any results like this:

if ($resultĀ != NULL)  

Be careful with derived attributes

A given query returns a max of one derived attribute when using JSON as the return format. If 3 derived attributes are requested, the first two are ignored and the last one is returned with the name "anon".

For example, the rql:

SELECT "aa", "bb", "cc", uid FROM user  

is effectively this in SQL:

 SELECT "cc" AS anon, uid FROM user  

If you use XML as the return type, all requested derived attribs will be returned with the name "anon".

Another difference between JSON and XML formats is that the order of the requested attributes is preserved in XML but not JSON.