子查询即可
SELECT (SELECT name FROM TA WHERE id = TB.id1) AS id1,
(SELECT name FROM TA WHERE id = TB.id2) AS id2
FROM TB
select c.name,d.name from (select a.id1 id1,a.id2 id2,a.name name from TA a,TB b where a.id1=b.id1) temp c
,TA d where c.id2=d.id2
SELECT T1.name as name1,T2.name as name2 FROM TA as T1,TA as T2,TB
WHERE T1.id = TB.id1 AND T2.id = TB.id2
--创建测试数据
create table #a(id int,name varchar(10))
insert into #a values(1,'A')
insert into #a values(2,'B')
insert into #a values(3,'C')
create table #b(id1 int,id2 int)
insert into #b values(1,2)
insert into #b values(2,1)
insert into #b values(2,3)
---------------实现代码部分----------------
select
t1.name as name1
,t2.name as name2
from
#b tt
left join #a t1 on tt.id1 =t1.id
left join #a t2 on tt.id2 =t2.id
select * from ta,tb where ta.id= tb.id1