Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding relation

Status
Not open for further replies.

kipv

Programmer
Joined
Apr 21, 2006
Messages
1
Location
CA
Hi,

I have a table:

id user1 user2


and I am looking for a way to select all the users that are connected to each other, for example:

id user1 user2
1 john bob
2 bob tracy
3 tracy greg
4 fred hanna
5 greg james

I want to see if john is connected to james, so the result should return:

id user1 user2
2 bob tracy
3 tracy greg
5 greg james


is something like this possible ?
 
Hi..i m also a beginer..we can do this by using self-joins..Consider the table name as Users then try this:

select u1.id, u1.user1, u1.user2 from users u, users u1 where u.user2=u1.user1;

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top