如果你的建表语句如下,就必须引用两次 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
( 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
但是至于那个执行时间快,不确定,具体执行下或看一下执行计划吧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
from worder er left join person a on er.id1=a.id
left join person b on er.id2=b.id