Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your post offers vague insight into the schema, so I will use some assumptions</p> <p>You can find all of the ids that match their friends via an IN statement. Since you already have them as numeric values with comma's you could do:</p> <pre><code>SELECT user_id FROM users_relationships WHERE relation_getter IN (126152,112238,123456) AND active = 1 </code></pre> <p>This will return ONLY the records of friends that match. You then could match the number of rows with the number of elements in the query to determine if they're friends or not. You could also just send to the ones that matched.</p> <p>EDIT</p> <pre><code>SELECT user_id FROM users_relationships WHERE relation_getter IN (126152,112238,123456) OR relation_setter IN (126152,112238,123456) AND active = 1 </code></pre> <p>This will return all user ID's of the person's friends be they the getter or setter and it's active.</p> <p>EDIT 2</p> <p><em>new table</em></p> <pre><code>relationships_members id FK (from users_relationships; not unique) user_id </code></pre> <p>Sample of relationships_members would be</p> <pre><code> id | user_id | relation_setter -------------------------------------- 1 12345 1 -------------------------------------- 1 98765 0 -------------------------------------- </code></pre> <p>Then if you queried, you would only receive users_relationships ID that were valid</p> <pre><code>select distinct a.id, b.user_id as friend from ( select distinct id as friend from relationships_members where user_id = {$logged_in_user} ) a, relationships_members b WHERE a.id = b.id and user_id IN (126152,112238,123456) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload