3

这里发生了什么?

我有两个表,test1 和 test2:

create table test1 (id1 int4 primary key);
create table test2 (id2 int4 primary key);

正如预期的那样,这个查询:

select id1 from test2;

产生语法错误:

ERROR:  column "id1" does not exist
LINE 1: select id1 from test2;

但是,当我尝试执行此查询时:

select * from test1 where id1 in (select id1 from test2);

PostgreSQL 没有抱怨,执行查询并给我:

 id1
-----
(0 rows)

这有什么逻辑吗?还是我应该提交错误报告?

4

1 回答 1

4

外部的列select在子选择中可见。

您的查询相当于:

select * 
from test1 
where test1.id1 in (select test1.id1 from test2);
于 2013-10-16T15:12:56.303 回答