此查询中的子查询无效。程序表不包含名为“calcfile”的列。正确的列名是'calc_file'。但是,当我运行查询时,我没有得到任何错误,结果就好像where子句不存在一样。我不应该得到一个错误而不是无效的结果?
select distinct result from calcdetl
where calcfile = (select calcfile from program where program = 'HIGLAS Program')
order by result
;
您的查询被解释为:
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;