从subselect中选择视图列(oracle,sql)

时间:2018-03-23 09:36:49

标签: sql oracle select subquery oracle12c

我选择了:

select c.ColA, c.ColB, c.ColC, c.ColD from table1 c
where c.ColB in (
                select colX from table2 where colZ in ('test', 'test2') and colV = 3
                );

如何在table2中显示 ColV

当我这样做时:

c.ColB in (select colX, colV from table2 where colZ in ('test', 'test2') and colV = 3)

我收到了错误:00913。00000 - "价值太多"

1 个答案:

答案 0 :(得分:1)

在这种情况下,您想要进行内部联接:

SELECT c.colA, c.colB, c.colC, c.colD, c2.colV
  FROM table1 c INNER JOIN table2 c2
    ON c.colB = c2.colX
 WHERE c2.colZ IN ('test', 'test2')
   AND c2.colV = 3;

根据经验,当您需要来自另一个表的列时,请使用JOIN条件;当你没有时,请使用EXISTSIN

希望这有帮助。

P.S。限定符INNER是不必要的,但我喜欢它,因为它使事情变得明确。

相关问题