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)
 InnerJoin

Author  Topic 

agpasam
Starting Member

2 Posts

Posted - 2009-02-26 : 01:07:07
I have two tables

Table1 Table2

EID SID EID Name

1 2 1 aaaaa
2 1 2 sssss

I want the result like this
EID NAME SID ALIASNAMESID
1 aaaa 2 ssss
2 ssss 1 aaaa

Can anyonle help this

Mangal Pardeshi
Posting Yak Master

110 Posts

Posted - 2009-02-26 : 01:29:10
[code]
SELECT A.eid, B.name, A.SID, c.Name
FROM Table1 A INNER JOIN Table2 B
ON A.eid = B.eid
INNER JOIN Table2 C
ON A.sid = C.Eid
[/code]

Mangal Pardeshi
http://mangalpardeshi.blogspot.com
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-02-26 : 01:44:11
try this too
declare @Table1 table(eid int , sid int)
insert into @table1
select 1,2 union all select 2,1

declare @Table2 table(eid int , name varchar(32))
insert into @table2
select 1,'aaaaa' union all select 2,'sssss'

select eid , (select name from @table2 where eid = t.eid ) as name,
sid, (select name from @table2 where eid = t.sid ) as name
from @table1 t
Go to Top of Page

agpasam
Starting Member

2 Posts

Posted - 2009-02-26 : 02:04:54
Hi
Thanks ALL for your valuable answer
I got it.
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-02-26 : 02:21:58
welcome
Go to Top of Page
   

- Advertisement -