使用inner-query-table连接表

时间:2014-03-28 07:22:35

标签: sql inner-query

请使用以下选择语句查看this SQL fiddle

select T1.VAL, ttemp.*
from T1, 
  (select rownum, t.* from (select * from T2 where t2.val = t1.val ) t) ttemp
where t1.val = ttemp.val
and t1.val > 2

在这里,我想将最外层的表与内层-2表连接起来,然后将t2.val > 2替换为t2.val = t1.val会导致

ORA-00904: "T1"."VAL": invalid identifier 

我认为不为where添加joinselect * from T2子句会导致全表扫描。不是吗?

1 个答案:

答案 0 :(得分:0)

也许你可以使用它:

SELECT rownum, t1.val, t2.NAME
FROM T1 t1
LEFT JOIN T2 t2 ON (t1.VAL = t2.VAL)
WHERE t1.VAL > 2