I have the following tables:
USERS
table
- id
- username
- password
- status
FRIENDS
table
- id
- user_id
- friend_id
- created
To find a users friends, I use:
SELECT f.friend_id,
u.username
FROM friends f
JOIN friends m ON m.user_id = f.friend_id
AND m.friend_id = f.user_id
JOIN users u ON u.user_id = f.friend_id
WHERE f.user_id = 1234
...which works great.
ISSUE
I can't figure out a similar query in the other way though, find all the users that aren't friends yet. It would have to be something along the lines of, get all the friends, get all the users, remove all users that are the friends to leave the remainder?