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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Retrieve Records

Author  Topic 

chava_sree
Yak Posting Veteran

56 Posts

Posted - 2008-06-05 : 19:53:21
Hi all

I've two tables
community, community_related.

I need to get community names for comm_relatedID from community table
where comm_id = 21 , please see my tables below

Community table Community Related
commID, comm_name comm_id comm_relatedID
21 test1 21 24
22 test2 21 22
23 test3 21 26
24 test 5 21 27
26 test6
27 test7

result am trying to display from community related table after joining community table on COMM_ID = 21 is

comm_id comm_relatedID comm_name
21 24 test5
21 22 test2
21 26 test6
21 27 test7

can anybody please help..with a query, am stuck at this point.

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-06-05 : 21:35:24
Try this:

select b.comm_id ,b.comm_relatedID ,a.comm_name
from dbo.Community Related b
left join dbo.Community a
on b.comm_relatedID = a.commID
Go to Top of Page
   

- Advertisement -