SQL view for acquaintance from table

I have a table for friends

PLAYER_ID    FRIEND_ID
----------------------
1            2
1            3         // 1 knows 3
3            1         // 3 knows 1
2            4

How can I create a view containing those acquaintances(know each other) for given player?

PLAYER_ID    FRIEND_ID
----------------------
1            3
3            1

thank you.

Answers


Here's the needed select:

select t1.PLAYER_id, t1.FRIEND_ID from tablename t1
inner join tablename t2 on t1.PLAYER_id = t2.FRIEND_ID and t2.PLAYER_id = t1.FRIEND_ID

select p1.player_id, p1.friend_Id
from player p1 
inner join player p2 on p1.player_id = p2.friend_id and p2.player_id = p1.friend_id

Need Your Help

SSRS 2008:How to hide a table row (Conditionally) based on category field

sql-server ssrs-2008

I am new to Sql Server Reporting Services. I have created my following report.

Refactoring tests vs implementation Rails and Capybara

ruby-on-rails rspec refactoring tdd capybara

What is the right way to refactor your tests so that there is no dependency on the implementation. Right now if lets say the title or the text in the link was changed then the tests would also nee...