此查询中的子查询无效。程序表中不包含名为' calcfile'的列。正确的列名是' calc_file'。但是,当我运行查询时,我没有得到任何错误,结果就好像where子句不存在一样。难道我没有收到错误而不是无效结果吗?
select distinct result from calcdetl
where calcfile = (select calcfile from program where program = 'HIGLAS Program')
order by result
;
答案 0 :(得分:4)
您的查询被解释为:
select distinct cd.result
from calcdetl cd
where cd.calcfile = (select cd.calcfile from program p where p.program = 'HIGLAS Program')
order by cd.result;
这完全有效 - 它是一个相关的子查询。
道德?当您的查询引用多个表时,始终使用限定列名。
如果你写了:
,你会收到错误select distinct cd.result
from calcdetl cd
where cd.calcfile = (select p.calcfile from program p where p.program = 'HIGLAS Program')
order by cd.result;