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)
 same join : different columns

Author  Topic 

cimon
Starting Member

4 Posts

Posted - 2009-06-22 : 13:50:25
hello


Table 1
ID_One Supervisor_ID
21 45
32 91
12 67

Table 2
ID Name
12 Jenny Jose
32 Jack Hason
67 Martin Lof
21 Jeremy sal
45 hina mat
91 Cliena Kite


I have to get the results as

21 Jeremy Sal 45 Hina Mat
32 jack Hason 91 Cliena Kite
so on

What's the best possible way to write the sql for this
i am trying to use join, but not sure how

select T1.id_one , T1.supervisor_id, T2.Name
FROM Table1 T1 LEFT OUTER JOIN
Table2 T2 ON T1.ID_One = T2.ID

To the above query how can I add T2.name again so that I get the name corresponding to supervisor id

thank you

cimon









rohitkumar
Constraint Violating Yak Guru

472 Posts

Posted - 2009-06-22 : 14:03:42
select T1.id_one , T1.supervisor_id, T2.Name, T3.Name
FROM Table1 T1
LEFT OUTER JOIN Table2 T2
ON T1.ID_One = T2.ID
LEFT OUTER JOIN Table2 T3
ON T1.Supervisor_ID = T3.ID
Go to Top of Page

cimon
Starting Member

4 Posts

Posted - 2009-06-22 : 14:15:34
quote:
Originally posted by rohitkumar

select T1.id_one , T1.supervisor_id, T2.Name, T3.Name
FROM Table1 T1
LEFT OUTER JOIN Table2 T2
ON T1.ID_One = T2.ID
LEFT OUTER JOIN Table2 T3
ON T1.Supervisor_ID = T3.ID




thank you

tat works
Go to Top of Page
   

- Advertisement -