Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Getting the second degree values from the table

Author  Topic 

Kotti
Posting Yak Master

129 Posts

Posted - 2009-12-18 : 01:59:30

Hello Friends,

I am having two tables,one is user table and other one is connections table.

User table
Id Name
140 kotti
145 john
150 prasad
170 sam
190 raj

connections table

Id MyPId MyCId
1 145 140
2 140 145
3 170 140
4 140 170
5 140 150
6 150 140
7 145 190
8 190 145

when i execute this query,i will get the MyCIds
select MyCId from connections where MyPId=140
I will this result
145
170
150

What i need is then i need to send the (145,170,150) to connections table and i need to get the result of the MyCId

All this should be in a single query.

Finally the result should be
MyCId Name
190 Raj

which excludes the MyCId 140.

Please help me to get the correct query.

If you need more explanation,i will explain.

Thanks in Advance.




divyaram
Posting Yak Master

180 Posts

Posted - 2009-12-18 : 02:11:50
hi KOtti,

i think this query will work.....

select connections.MyCId,user.name from user
inner join connections on user.id= connections.MyPId
where connections.MyPId=190

regards,
Divya
Go to Top of Page

Kotti
Posting Yak Master

129 Posts

Posted - 2009-12-18 : 02:21:57
quote:
Originally posted by divyaram

hi KOtti,

i think this query will work.....

select connections.MyCId,user.name from user
inner join connections on user.id= connections.MyPId
where connections.MyPId=190

regards,
Divya



Hello Divya,

Thanks for your reply.

I don't need the query like this,I need the second degree connections
I mean users of users

Thanks in Advance .
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-12-18 : 02:22:46
Clearly post your expected output!!

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

divyaram
Posting Yak Master

180 Posts

Posted - 2009-12-18 : 02:30:00
what is expected output????
Go to Top of Page

Kotti
Posting Yak Master

129 Posts

Posted - 2009-12-18 : 02:43:52
Expected output is
MyCId Name
190 Raj
Go to Top of Page
   

- Advertisement -