# Query for all of someone's friends

**URL:** <https://forum.kirupa.com/t/query-for-all-of-someones-friends/303269>\
**Category:** programming\
**Created:** [January 18, 2010, 3:47am UTC](https://forum.kirupa.com/t/query-for-all-of-someones-friends/303269 "2010-01-18T03:47:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NeoDreamer](https://avatars.discourse-cdn.com/v4/letter/n/ccd318/32.png) [@NeoDreamer](https://forum.kirupa.com/u/NeoDreamer)\
**Post date:** [January 18, 2010, 3:47am UTC](https://forum.kirupa.com/t/query-for-all-of-someones-friends/303269/1 "2010-01-18T03:47:57Z")

</div>

TABLE user

```auto

userId username
14 john
2 sally
3 mike

```

Table friend

```auto

userId friendId
14 2
3 14
3 2

```

I would like to query for the userId and username of all of john’s friends. I attempted to use this query:

```auto

(
   SELECT u.username, u.userId
   FROM user AS u, friend AS f
   WHERE f.userId = 14
   AND f.friendId = u.userId
)
UNION
(
   SELECT u.username, u.userId
   FROM user AS u, friend AS f
   WHERE f.friendId = 14
   AND f.userId = u.userId
)

```

But this only returned 2(sally). It should be returning 2(sally) and 3(mike). Is the problem with the second clause? I tried by it itself and it returned an empty result.
