帮助了解为什么错误的内部查询不会使外部查询错误
以下查询返回19
proc sql;
select count(distinct name)
from sashelp.class
where name in (select name from sashelp.iris
where species is not missing)
;quit; *returns 19;
但是,我希望它会返回错误,因为内部查询确实会返回错误(因为在sashelp.iris中找不到“名称”列):
proc sql;
select name from sashelp.iris
where species is not missing
;quit; *returns an error (column not found);
有人可以解释一下为什么我一开始没有收到错误消息的逻辑吗?
答案 0 :(得分:5)
您没有将对name
的引用进行限定,因此它使用了唯一的变量,即名称。因此,您运行了以下查询:
proc sql;
select count(distinct A.name)
from sashelp.class A
where A.name in
(select A.name
from sashelp.iris B
where B.species is not missing
)
;
quit;
如果您实际上从IRIS引用了NAME,则会收到错误消息。
220 proc sql;
221 select count(distinct A.name)
222 from sashelp.class A
223 where A.name in
224 (select B.name
225 from sashelp.iris B
226 where B.species is not missing
227 )
228 ;
ERROR: Column name could not be found in the table/view identified with the correlation name B.
ERROR: Unresolved reference to table/correlation name B.
229 quit;