```
SELECT
    FRIEND.friend_two AS possible_friend, USERS.username AS possible_username
FROM
    user_friends FRIEND, users USERS
WHERE 
    FRIEND.friend_one IN (SELECT friend_two FROM user_friends WHERE friend_one = :id)
    AND FRIEND.friend_two NOT IN (SELECT friend_two FROM user_friends WHERE friend_one = :id)
    AND NOT FRIEND.friend_two = :id
GROUP BY possible_friend

```

users

```
+------------+------------------+
|     id     |     username     |
+------------+------------------+
|     10     |       Josh       |
+------------+------------------+
|     20     |     Steward      |
+------------+------------------+
|     30     |      Fenton      | 
+------------+------------------+

```

user\_friends

```
+------------+------------+------------+------------+
| friend_id  | friend_one | friend_two |    Role    |
+------------+------------+------------+------------+
| ramdom_id  |     10     |     10     |     me     +
+------------+------------+------------+------------+
| ramdom_id  |     20     |     20     |     me     +
+------------+------------+------------+------------+
| ramdom_id  |     10     |     20     |   friend   +
+------------+------------+------------+------------+
| ramdom_id  |     20     |     30     |   friend   +
+------------+------------+------------+------------+

friend_one = 10 (Josh)      -> follows -> friend_two = 20 (Steward)
friend_one = 20 (Steward)   -> follows -> friend_two = 30 (Fenton)

```

var\_dump($query); displays the following text.

```
Array ( [possible_friend] => 30 [possible_username] => STEWARD )

```

The error in the var\_dump is that I already follow Steward, and Steward has an id of (20). What I'd like to show is

```
Array ( [possible_friend] => 30 [possible_username] => FENTON )

```

Since Fenton has an id of `(30)` and `Josh(10)` who is logged in is not following Fenton.

If `Josh(10)` is logged in, it'll suggest `JOSH` to follow `Fenton(30)` since `Steward(20)` follows `Fenton(30)` while `Josh(10)` does not.

When this query comes to closure, it's purpose is to suggest Friends of my Friends for the user to follow as explained above.

How do I use GROUP BY to make sure that the user that's being suggested has the correct username being printed as I explained with the var\_dump for FENTON.
As of the moment it's retrieving random usernames of users that I already follow and not by 'AS possible\_friends' in the query.

---