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
 Need query!

Author  Topic 

ArpitNarula
Starting Member

16 Posts

Posted - 2011-02-09 : 08:26:04
Hi Guys

There are two tables A and B.
Table A
id name
1 a
2 b
3 c
4 d


Table B
loc aid aid 2
qw 1 3
we 1 1
rt 2 2
ty 3 2

And I need a query to produce output like
loc aid aid 2
qw a c
we a a
rt b b
ty c b

Thanks in Advance

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-02-09 : 08:29:41
select t1.loc,t2.name,t3.name from tableB as t1 inner join tableA as t2 on t1.aid=t2.id inner join tableA as t3 on t1.aid2=t3.id

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -