0

I have a table "friendship" like this

user_id
friend_id

For each friendship I make one record instead of two.

---------------------
user_id | friend_id |
--------------------
  1     |   2       |
--------------------

And I Don't add (2 , 1) into table. So, I need to get all the friends of friends list including those who are already in my friend list preferably without subqueries. Any suggestions ? Thanks :)

Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
vazgen
  • 83
  • 1
  • 1
  • 10

1 Answers1

0

Are you looking for something like this?

SELECT f2.friend_id
  FROM friendship f1 JOIN friendship f2
    ON f1.friend_id = f2.user_id 
 WHERE f1.user_id = 1

Here is SQLFiddle demo

peterm
  • 91,357
  • 15
  • 148
  • 157