Query with join doesn't work
A couple of things...firstly

$query-&gt;condition('data.fk_users_uid', !$uid);


!$uid returns false when used on a positive non-zero integer in PHP (and true for zero, the anonymous user).

You probably meant:

$query-&gt;condition('data.fk_users_uid', $uid, '&lt;&gt;');


Secondly, you're using the same alias for both tables. That'll never work. Change the one in the join to data2 or something:

$query-&gt;join('foolzz_user_has_user', 'data2', 'data2.fk_user1=:uid OR data2.fk_user2=:uid', array(':uid' =&gt; $uid));