如果你的建表语句如下,就必须引用两次 person  表create table t
( description varchar(30) , 
 id1 int ,
id2 int 
)
另外,你的语句应该这样写
select description,
id1,
(select  人名  from person son where er.id1=son.id)id1-人名,
id2,
(select  人名  from person son where er.id2=son.id)id2-人名  
 from   worder er

解决方案 »

  1.   

    提供一种其他的写法,列转行,再行转列,B表访问次数少了
    但是至于那个执行时间快,不确定,具体执行下或看一下执行计划吧TABLEA code1、code2、code3
    TABLEB code、codename
    SELECT MAX(DECODE(A.CONAME,'code1',B.codeName)),
         MAX(DECODE(A.CONAME,'code2',B.codeName)),
         MAX(DECODE(A.CONAME,'code3',B.codeName))
    FROM
       (select code1 as code,'code1' as colname,rowid as id from TABLEA
       union all
       select code2 as code,'code2' as colname,rowid as id from TABLEA
       union all
       select code3 as code,'code3' as colname,rowid as id from TABLEA) A,TABLEB B
    WHERE A.CODE=B.CODE
    GROUP BY A.ID
      

  2.   

    子查询换成连接会不会清晰一点?select description,id1,a.人名   id1人名,id2,b.人名  id2人名  
     from   worder er left join person a on er.id1=a.id 
    left join person b on er.id2=b.id