了解基本的SQL查询

Viv*_*vek 2 sql oracle subquery

我有一个查询

SELECT tran_number
  FROM table_a WHERE customer_id IN
          (SELECT customer_id 
             FROM table_b
            WHERE customer_key = 89564
                  AND (   other_phn_area_code
                       || other_phnum_pfx_num
                       || other_phnum_sfx_num IN
                          (123456789)))
       AND phn_area_code || phnum_pfx_num || phnum_sfx_num IN (123456789)
Run Code Online (Sandbox Code Playgroud)

上面的代码工作正常.关注的是内部查询(下面单独复制内部查询)...

(SELECT customer_id 
                 FROM table_b
                WHERE customer_key = 89564
                      AND (   other_phn_area_code
                           || other_phnum_pfx_num
                           || other_phnum_sfx_num IN
                              (123456789)))
Run Code Online (Sandbox Code Playgroud)

当我执行此查询时,我收到错误customer_id: invalid identifier.实际上,table_b没有任何字段命名customer_id.如果是这样,那么当我将它用作上面的内部查询时,它是如何工作的,没有任何问题.

请帮我理解这个.

数据库详情如下

Oracle 11G Enterprise edition 11.2.0.2.0
PL/SQL Release 11.2.0.2.0
Run Code Online (Sandbox Code Playgroud)

jue*_*n d 7

如果where那内选择条件具有的结果,则该列customer_idtable_a将被选择.如果没有,则不会被选中.外部选择检查in条件.这就像说:"只有在内部选择返回true时才返回一些东西."